Module credentials
The following functions use a resource file to store credentials information
for the user. The default location of this resource file is
.quantuminspire/qirc
in the user’s home directory.
This default location is indicated with DEFAULT_QIRC_FILE in the following function signatures.
- load_account(filename: str = DEFAULT_QIRC_FILE) str | None [source]
Try to load an earlier stored Quantum Inspire token from file or environment.
Load the token when found. This method looks for the token in two locations, in the following order:
In the environment variable (
QI_TOKEN
).In the file with filename given or, when not given, the default resource file
.quantuminspire/qirc
in the user’s home directory.
- Parameters:
filename (str) – full path to the resource file. If no filename is given, the default resource file
.quantuminspire/qirc
in the user’s home directory is used.- Returns:
The Quantum Inspire token or None when no token is found.
- Return type:
str | None
- read_account(filename: str = DEFAULT_QIRC_FILE) str | None [source]
Try to read an earlier stored Quantum Inspire token from file.
his method looks for the token in the file with filename given or, when no filename is given, the default resource file
.quantuminspire/qirc
in the user’s home directory.- Parameters:
filename (str) – full path to the resource file. If no filename is given, the default resource file
.quantuminspire/qirc
in the user’s home directory is used.- Returns:
The Quantum Inspire token or None when no token is found or token is empty.
- Return type:
str | None
- store_account(token: str, filename: str = DEFAULT_QIRC_FILE, overwrite: bool = False) None [source]
Store the token in a resource file.
Replace an existing token only when overwrite=True.
- Parameters:
token (str) – the Quantum Inspire token to store to disk.
filename (str) – full path to the resource file. If no filename is given, the default resource file
.quantuminspire/qirc
in the user’s home directory is used.overwrite (bool) – overwrite an existing token.
- Return type:
None
- delete_account(token: str, filename: str = DEFAULT_QIRC_FILE) None [source]
Remove the token from the resource file.
- Parameters:
token (str) – the Quantum Inspire token to remove.
filename (str) – full path to the resource file. If no filename is given, the default resource file
.quantuminspire/qirc
in the user’s home directory is used.
- Return type:
None
- save_account(token: str, filename: str = DEFAULT_QIRC_FILE) None [source]
Save the token to a file.
Save the token to the file with filename given, otherwise save to the default resource file. An existing token is overwritten. Use
store_account()
to prevent overwriting an existing token.- Parameters:
token (str) – the Quantum Inspire token to save.
filename (str) – full path to the resource file. If no filename is given, the default resource file
.quantuminspire/qirc
in the user’s home directory is used.
- Return type:
None
- enable_account(token: str) None: [source]
Save the token to the internal environment, that will be used by load_account for the session.
When a token was already loaded from the system environment it is overwritten. The system environment is not effected.
- Parameters:
token (str) – the Quantum Inspire token to be used by
load_account()
for the session.- Return type:
None
- get_token_authentication(token: str | None = None) TokenAuthentication: [source]
Set up token authentication for Quantum Inspire to be used in the API.
- Parameters:
token (str | None) – the Quantum Inspire token to set in TokenAuthentication. When no token is given, the token returned from
load_account()
is used.- Returns:
The token authentication for Quantum Inspire.
- Return type:
TokenAuthentication
- get_basic_authentication(email: str, password: str) BasicAuthentication: [source]
Set up basic authentication for Quantum Inspire to be used in the API.
- Parameters:
email (str) – a valid email address.
password (str) – password for the account.
- Returns:
The basic authentication for Quantum Inspire.
- Return type:
BasicAuthentication
- get_authentication() Union[TokenAuthentication, BasicAuthentication]: [source]
Gets the authentication for connecting to the Quantum Inspire API.
First it tries to load a token, saved earlier. When a token is not found it tries to login with basic authentication read from the environment variables QI_EMAIL and QI_PASSWORD. When the environment variables are not both set, email and password are read from standard input.
- Returns:
The token or basic authentication for Quantum Inspire.
- Return type:
TokenAuthentication | BasicAuthentication