Client Configuration¶
The configuration for Backend.AI API includes the endpoint URL prefix, API keypairs (access and secret keys), and a few others.
There are two ways to set the configuration:
Setting environment variables before running your program that uses this SDK.
Manually creating
APIConfig
instance and creating sessions with it.
The list of supported environment variables are:
BACKEND_ENDPOINT
BACKEND_ACCESS_KEY
BACKEND_SECRET_KEY
BACKEND_VFOLDER_MOUNTS
Other configurations are set to defaults.
Note that when you use our client-side Jupyter integration,
BACKEND_VFOLDER_MOUNTS
is the only way to attach your virtual folders to the
notebook kernels.
-
ai.backend.client.config.
get_env
(key, default=None, clean=<function <lambda>>)[source]¶ Retrieves a configuration value from the environment variables. The given key is uppercased and prefixed by
"BACKEND_"
and then"SORNA_"
if the former does not exist.- Parameters
key (
str
) – The key name.default (
Optional
[Any
]) – The default value returned when there is no corresponding environment variable.clean (
Callable
[[str
],Any
]) – A single-argument function that is applied to the result of lookup (in both successes and the default value for failures). The default is returning the value as-is.
- Returns
The value processed by the clean function.
-
ai.backend.client.config.
get_config
()[source]¶ Returns the configuration for the current process. If there is no explicitly set
APIConfig
instance, it will generate a new one from the current environment variables and defaults.
-
ai.backend.client.config.
set_config
(conf)[source]¶ Sets the configuration used throughout the current process.
-
class
ai.backend.client.config.
APIConfig
(*, endpoint=None, version=None, user_agent=None, access_key=None, secret_key=None, hash_type=None, vfolder_mounts=None, skip_sslcert_validation=None)[source]¶ Represents a set of API client configurations. The access key and secret key are mandatory – they must be set in either environment variables or as the explicit arguments.
- Parameters
endpoint (
Union
[URL
,str
,None
]) – The URL prefix to make API requests via HTTP/HTTPS.user_agent (
Optional
[str
]) – A custom user-agent string which is sent to the API server as aUser-Agent
HTTP header.hash_type (
Optional
[str
]) – The hash type to generate per-request authentication signatures.vfolder_mounts (
Optional
[Iterable
[str
]]) – A list of vfolder names (that must belong to the given access key) to be automatically mounted upon anyKernel.get_or_create()
calls.
-
DEFAULTS
= {'endpoint': 'https://api.backend.ai', 'hash_type': 'sha256', 'version': 'v4.20190315'}¶ The default values except the access and secret keys.