Configuration

ai.backend.client.config.get_env(key, default=Undefined.token, *, clean=<function default_clean>)

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 (Union[str, Mapping, Undefined]) – The default value returned when there is no corresponding environment variable.

  • clean (Callable[[Any], ~T]) – 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.

Return type

~T

Returns

The value processed by the clean function.

ai.backend.client.config.get_config()

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)

Sets the configuration used throughout the current process.

class ai.backend.client.config.APIConfig(*, endpoint=None, endpoint_type=None, domain=None, group=None, storage_proxy_address_map=None, version=None, user_agent=None, access_key=None, secret_key=None, hash_type=None, vfolder_mounts=None, skip_sslcert_validation=None, connection_timeout=None, read_timeout=None, announcement_handler=None)

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[str, URL, None]) – The URL prefix to make API requests via HTTP/HTTPS. If this is given as str and contains multiple URLs separated by comma, the underlying HTTP request-response facility will perform client-side load balancing and automatic fail-over using them, assuming that all those URLs indicates a single, same cluster. The users of the API and CLI will get network connection errors only when all of the given endpoints fail – intermittent failures of a subset of endpoints will be hidden with a little increased latency.

  • endpoint_type (Optional[str, None]) – Either "api" or "session". If the endpoint type is "api" (the default if unspecified), it uses the access key and secret key in the configuration to access the manager API server directly. If the endpoint type is "session", it assumes the endpoint is a Backend.AI console server which provides cookie-based authentication with username and password. In the latter, users need to use backend.ai login and backend.ai logout to manage their sign-in status, or the API equivalent in login() and logout() methods.

  • version (Optional[str, None]) – The API protocol version.

  • user_agent (Optional[str, None]) – A custom user-agent string which is sent to the API server as a User-Agent HTTP header.

  • access_key (Optional[str, None]) – The API access key. If deliberately set to an empty string, the API requests will be made without signatures (anonymously).

  • secret_key (Optional[str, None]) – The API secret key.

  • hash_type (Optional[str, None]) – The hash type to generate per-request authentication signatures.

  • vfolder_mounts (Optional[Iterable[str], None]) – A list of vfolder names (that must belong to the given access key) to be automatically mounted upon any Kernel.get_or_create() calls.

DEFAULTS: Mapping[str, Union[str, Mapping]] = {'connection_timeout': '10.0', 'domain': 'default', 'endpoint': 'https://api.backend.ai', 'endpoint_type': 'api', 'group': 'default', 'hash_type': 'sha256', 'read_timeout': '0', 'storage_proxy_address_map': {}, 'version': 'v6.20220315'}

The default values for config parameterse settable via environment variables xcept the access and secret keys.

property endpoint: URL

The currently active endpoint URL. This may change if there are multiple configured endpoints and the current one is not accessible.

Return type

URL

property endpoints: Sequence[URL]

All configured endpoint URLs.

Return type

Sequence[URL]

property endpoint_type: str

The configured endpoint type.

Return type

str

property domain: str

The configured domain.

Return type

str

property group: str

The configured group.

Return type

str

property storage_proxy_address_map: Mapping[str, str]

The storage proxy address map for overriding.

Return type

Mapping[str, str]

property user_agent: str

The configured user agent string.

Return type

str

property access_key: str

The configured API access key.

Return type

str

property secret_key: str

The configured API secret key.

Return type

str

property version: str

The configured API protocol version.

Return type

str

property hash_type: str

The configured hash algorithm for API authentication signatures.

Return type

str

property vfolder_mounts: Sequence[str]

The configured auto-mounted vfolder list.

Return type

Sequence[str]

property skip_sslcert_validation: bool

Whether to skip SSL certificate validation for the API gateway.

Return type

bool

property connection_timeout: float

The maximum allowed duration for making TCP connections to the server.

Return type

float

property read_timeout: float

The maximum allowed waiting time for the first byte of the response from the server.

Return type

float

property announcement_handler: Optional[Callable[[str], None]]

The announcement handler to display server-set announcements.

Return type

Optional[Callable[[str], None], None]