Products & servicesTechnologyCompanyInvestor relationsResource libraryNews
Contact us
Resource library
    Introduction to Dirac-3 home
    Dirac-3 Developer Beginner Guide
    Dirac-3 user guide
    Dirac-3 spec sheet
    Entropy Quantum Computing overview
    Multibody formulation
    qci-client software package
      Getting Started
      Basic Usage
      qci-client
      Dirac-3S (dirac-3s)
      Dependencies
      Index
      Module Index
    eqc-direct software package

Couldn’t find what you are looking for? Reach out to technical support.

Contact support
Privacy PolicyCookie PolicyTerms of UseForward Looking StatementsAccessibility Statement
Terms and Conditions of SaleEnd User License Agreement

© 2018-2026 Quantum Computing Inc.

Download

Source code for qci_client.utilities

  • # Copyright 2023-2024, Quantum Computing Incorporated
  • """Package-wide utilities."""
  • from datetime import datetime, timezone
  • import os
  • import requests
  • [docs]
  • def env_bool(*, name: str, default: bool) -> bool:
  • """
  • Read a boolean from an environment variable, falling back to default if unset.
  • Values are parsed case-insensitively; "1", "true", "t", "yes", "y", and "on" are
  • True, while "0", "false", "f", "no", "n", and "off" are False. Any other value
  • (including an empty string) falls back to default.
  • :param name: name of environment variable to read
  • :param default: value to return if variable is unset or unparseable
  • """
  • value = os.getenv(name)
  • if value is None:
  • return default
  • normalized = value.strip().lower()
  • if normalized in {"1", "true", "t", "yes", "y", "on"}:
  • return True
  • if normalized in {"0", "false", "f", "no", "n", "off"}:
  • return False
  • return default
  • [docs]
  • def raise_for_status(*, response: requests.Response) -> None:
  • """
  • Wrap requests method of same name to include response text in exception message.
  • :param response: a response from any API call using the requests package
  • """
  • try:
  • # The requests package does special handling here, so build off of this.
  • response.raise_for_status()
  • except requests.HTTPError as err:
  • # Include response body in exception message to aid user understanding.
  • raise requests.HTTPError(
  • str(err) + f" with response body: {response.text}"
  • ) from err
  • [docs]
  • def log_to_console(*, log: str, verbose: bool = True) -> None:
  • """If verbose is true, then print log with timestamp prefix."""
  • if verbose:
  • print(f"{datetime.now().strftime('%Y-%m-%d %H:%M:%S')} - {log}")
  • [docs]
  • def now_utc_ms() -> str:
  • """Get current time in UTC with microsecond (i.e., maximum) precision."""
  • return datetime.now(timezone.utc).strftime("%Y-%m-%dT%H:%M:%S.%fZ")
Next page

Content

  • Source code for qci_client.utilities