qcs_api_client.client
#
Submodules#
Package Contents#
Classes#
Implements |
|
This configures how |
|
A user's settings and secrets along with a specified profile name. |
|
The user's full set of QCS secrets. |
|
A set of credentials containing a |
|
TokenPayload represents a response from the OAuth2 POST /token endpoint. |
|
Generic enumeration. |
|
Specifies an OAuth2 authorization server against which to refresh tokens. |
|
A fully parsed settings configuration file. |
|
Specifies the authorization server, credentials, and API URL. |
|
Section of a profile specifying per-application settings. |
|
Functions#
|
Yield a client object suitable for use with the qcs_api_client.sync API functions. |
|
Yield a client object suitable for use with the qcs_api_client.asyncio API functions. |
- class qcs_api_client.client.QCSAuth(client_configuration: qcs_api_client.client._configuration.QCSClientConfiguration, auth_configuration: QCSAuthConfiguration = None)#
Bases:
httpx.Auth
Implements
httpx.Auth
sync_auth_flow
andasync_auth_flow
.If the
QCSClientConfiguration
that initializes this class has a validTokenPayload
onQCSClientConfiguration.credentials
, it will set the a refreshed access token as a Bearer token on the Authorization header of outgoing requests.Access tokens are refreshed via OAuth2 refresh mechanism as indicated by
QCSAuthConfiguration
.- sync_refresh_token()#
- sync_auth_flow(request)#
- async async_refresh_token()#
- async async_auth_flow(request)#
- class qcs_api_client.client.QCSAuthConfiguration#
Bases:
pydantic.BaseModel
This configures how
QCSAuth
implements its access token refresh mechanism.- pre :bool = False#
Pre-emptively refresh access tokens.
When set to True, this will check the access token’s expiration and refresh when necessary before setting the access token in the outgoing Authorization header.
- post :bool = True#
Refresh access tokens based on response status code.
When set to True, this will check responses for the status codes configured in
post_refresh_statuses
. On match,QCSAuth
will refresh the access token and retry the request.
- post_refresh_statuses :Set[int]#
Response status codes which indicates a possible expired token payload.
This contains a set of HTTP status codes which
QCSAuth
will check on responses when post is set to True.
- exception qcs_api_client.client.QCSAuthRefreshError(response: httpx.Response)#
Bases:
Exception
Common base class for all non-exit exceptions.
Initialize self. See help(type(self)) for accurate signature.
- qcs_api_client.client.build_sync_client(*, configuration: Optional[qcs_api_client.client._configuration.QCSClientConfiguration] = None, client_kwargs: Optional[dict] = None) httpx.Client #
Yield a client object suitable for use with the qcs_api_client.sync API functions.
- async qcs_api_client.client.build_async_client(*, configuration: Optional[qcs_api_client.client._configuration.QCSClientConfiguration] = None, client_kwargs: Optional[dict] = None) httpx.AsyncClient #
Yield a client object suitable for use with the qcs_api_client.asyncio API functions.
- class qcs_api_client.client.QCSClientConfiguration#
Bases:
pydantic.main.BaseModel
A user’s settings and secrets along with a specified profile name.
This class contains a full representation of user specified
QCSClientConfigurationSecrets
andQCSClientConfigurationSettings
, as well as aprofile_name
which indicates whichQCSClientConfigurationSettingsProfile
to access withinQCSClientConfigurationSettings.profiles
.Typically, clients will simply call
QCSClientConfiguration.load
, to initialize this class from the specified secrets and settings paths.- profile_name :str#
- secrets :qcs_api_client.client._configuration.secrets.QCSClientConfigurationSecrets#
- settings :qcs_api_client.client._configuration.settings.QCSClientConfigurationSettings#
- property auth_server qcs_api_client.client._configuration.settings.QCSAuthServer #
Returns the configured authorization server.
self.profile.auth_server_name
serves as key toQCSClientConfigurationSettings.auth_servers
.- Returns
The specified
QCSAuthServer
.- Raises
QCSClientConfigurationError – If
QCSClientConfigurationSettings.auth_servers
does not have a value for the authorization server name.
- property credentials qcs_api_client.client._configuration.secrets.QCSClientConfigurationSecretsCredentials #
Returns the configured
QCSClientConfigurationSecretsCredentials
self.profile.credentials_name
serves as key toQCSClientConfigurationSecrets.credentials
.- Returns
The specified
QCSClientConfigurationSecretsCredentials
.- Raises
QCSClientConfigurationError – If
QCSClientConfigurationSettings.credentials
does not have a value for the specified credentials name.
- property profile qcs_api_client.client._configuration.settings.QCSClientConfigurationSettingsProfile #
Returns the configured
QCSClientConfigurationSettingsProfile
.self.profile_name serves as key to
QCSClientConfigurationSettingsProfile.profiles
.- Returns
The specified
QCSClientConfigurationSettingsProfile
.- Raises
QCSClientConfigurationError – If
QCSClientConfigurationSettings.profiles
does not have a value for the specified profile name.
- classmethod load(profile_name: Optional[str] = None, settings_file_path: Optional[os.PathLike] = None, secrets_file_path: Optional[os.PathLike] = None) QCSClientConfiguration #
Loads a fully specified
QCSClientConfiguration
from file.It evaluates attribute values according to the following precedence: argument value > environment variable > default value.
- Parameters
profile_name – [env: QCS_PROFILE_NAME] The name of the profile referenced in the fully parsed
QCSClientConfigurationSettings.profiles
. If the profile name does not exist onQCSClientConfigurationSettings
,QCSClientConfiguration.profile
will raise an error. The default value is “default”, which may be overridden byQCSClientConfigurationSettings.default_profile_name
.settings_file_path – [env: QCS_SETTINGS_FILE_PATH] The file path from which to parse
QCSClientConfigurationSettings
. This file must exist in TOML format. The default value is~/.qcs/settings.toml
.secrets_file_path – [env: QCS_SECRETS_FILE_PATH] The file path from which to parse
QCSClientConfigurationSecrets
. This file must exist in TOML format. The default value is~/.qcs/secrets.toml
.
- Returns
A fully specified
QCSClientConfiguration
, whichQCSAuth
may use for adding refreshed OAuth2 access tokens to outgoing HTTP requests.
- exception qcs_api_client.client.QCSClientConfigurationError#
Bases:
Exception
Common base class for all non-exit exceptions.
Initialize self. See help(type(self)) for accurate signature.
- class qcs_api_client.client.QCSClientConfigurationSecrets#
Bases:
qcs_api_client.client._configuration.file.QCSClientConfigurationFile
The user’s full set of QCS secrets.
This class maps
QCSClientConfigurationSecretsCredentials
by user specified names. Each set of credentials, in turn, contains aTokenPayload
.- credentials :Dict[str, QCSClientConfigurationSecretsCredentials]#
- update_token(*, credentials_name: str, token: TokenPayload) None #
Update the value of a token payload in memory and (if appropriate) on disk.
- class qcs_api_client.client.QCSClientConfigurationSecretsCredentials#
Bases:
pydantic.BaseModel
A set of credentials containing a
TokenPayload
.- token_payload :Optional[TokenPayload]#
- property access_token Optional[str] #
- property refresh_token Optional[str] #
- class qcs_api_client.client.TokenPayload#
Bases:
pydantic.BaseModel
TokenPayload represents a response from the OAuth2 POST /token endpoint.
It contains an access_token which may be set as a Bearer token in the Authorization header on HTTP requests to the QCS API.
QCSAuth
will use therefresh_token
to refresh theaccess_token
if the token expires.- refresh_token :Optional[str]#
- access_token :Optional[str]#
- scope :Optional[str]#
- expires_in :Optional[int]#
- id_token :Optional[str]#
- token_type :Optional[str]#
- get_access_token_claims(key: Union[None, bytes, str] = None)#
Return the claims within the encoded access token.
If a JWK is provided as
key
, verify the claims as well. If no key is provided, be aware that the returned claims might be forged or invalid.
- property access_token_expires_at Optional[datetime.datetime] #
Return the datetime that the token expires (if any).
- should_refresh() bool #
Return True if the token is past or nearing expiration and should be refreshed.
- class qcs_api_client.client.QCSAccountType#
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- user = user#
- group = group#
- class qcs_api_client.client.QCSAuthServer#
Bases:
pydantic.BaseModel
Specifies an OAuth2 authorization server against which to refresh tokens.
- client_id :str#
- issuer :str#
- authorize_url()#
- token_url()#
- static scopes()#
- class qcs_api_client.client.QCSClientConfigurationSettings#
Bases:
qcs_api_client.client._configuration.file.QCSClientConfigurationFile
A fully parsed settings configuration file.
This contains all of the user’s configured authorization servers and profiles. It may optionally contain a
default_profile_name
to use to override the “default” value.QCSClientConfiguration
keys into these configured values when instantiated.- default_profile_name :str = default#
Which profile to select settings from when none is specified.
See
QCSClientConfiguration.load
.
- profiles :Dict[str, QCSClientConfigurationSettingsProfile]#
All available configuration profiles, keyed by name
- auth_servers :Dict[str, QCSAuthServer]#
All available authorization servers, keyed by name
- class qcs_api_client.client.QCSClientConfigurationSettingsProfile#
Bases:
qcs_api_client.client._configuration.environment.EnvironmentModel
Specifies the authorization server, credentials, and API URL.
The attributes of this class can be used to initialize an
httpx.Client
with the correct base URL and theQCSAuth
middleware for making authenticated API calls against the QCS API.QCSClientConfigurationSettings
may contain several profiles, whichQCSClientConfiguration.profile_name
may key into.- api_url :pydantic.networks.HttpUrl = https://api.qcs.rigetti.com#
URL of the QCS API to use for all API calls
- auth_server_name :str = default#
Which of the configured
QCSClientConfigurationSettings.auth_servers
to use
- applications :QCSClientConfigurationSettingsApplications#
Application-specific configuration values
- credentials_name :str = default#
Which of the configured
QCSClientConfigurationSecrets.credentials
to use and update
- account_id :Optional[str]#
Account ID on behalf of which to make requests. If set to
None
, QCS services will use your personal user account. Clients may also set this to a QCS group name for which they are authorized to make requests.
- account_type :Optional[QCSAccountType]#
Account type on behalf of which to make requests. When setting the
account_id
to a group name, this must be set toAccountType.group
.
- class qcs_api_client.client.QCSClientConfigurationSettingsApplications#
Bases:
pydantic.BaseModel
Section of a profile specifying per-application settings.
- cli :QCSClientConfigurationSettingsApplicationsCLI#
- pyquil :QCSClientConfigurationSettingsApplicationsPyquil#
- class qcs_api_client.client.QCSClientConfigurationSettingsApplicationsCLI#
Bases:
qcs_api_client.client._configuration.environment.EnvironmentModel
- verbosity :str =#