Client Session¶
This module is the first place to begin with your Python programs that use Backend.AI API functions.
The high-level API functions cannot be used alone – you must initiate a client session first because each session provides proxy attributes that represent API functions and run on the session itself.
To achieve this, during initialization session objects internally construct new types
by combining the BaseFunction
class with the
attributes in each API function classes, and makes the new types bound to itself.
Creating new types every time when creating a new session instance may look weird,
but it is the most convenient way to provide class-methods in the API function
classes to work with specific session instances.
When designing your application, please note that session objects are intended to live long following the process’ lifecycle, instead of to be created and disposed whenever making API requests.
-
class
ai.backend.client.session.
BaseSession
(*, config=None)[source]¶ The base abstract class for sessions.
-
config
¶ The configuration used by this session object.
-
-
class
ai.backend.client.session.
Session
(*, config=None)[source]¶ An API client session that makes API requests synchronously. You may call (almost) all function proxy methods like a plain Python function. It provides a context manager interface to ensure closing of the session upon errors and scope exits.
-
AgentWatcher
¶ The
AgentWatcher
function proxy bound to this session.
-
Auth
¶ The
Auth
function proxy bound to this session.
-
EtcdConfig
¶ The
EtcdConfig
function proxy bound to this session.
-
Domain
¶ The
Domain
function proxy bound to this session.
-
Group
¶ The
Group
function proxy bound to this session.
-
Image
¶ The
Image
function proxy bound to this session.
-
Resource
¶ The
Resource
function proxy bound to this session.
-
KeypairResourcePolicy
¶ The
KeypairResourcePolicy
function proxy bound to this session.
-
User
¶ The
User
function proxy bound to this session.
-
config
¶ The configuration used by this session object.
-
ScalingGroup
¶ The
ScalingGroup
function proxy bound to this session.
-
close
()[source]¶ Terminates the session. It schedules the
close()
coroutine of the underlying aiohttp session and then enqueues a sentinel object to indicate termination. Then it waits until the worker thread to self-terminate by joining.
-
worker_thread
¶ The thread that internally executes the asynchronous implementations of the given API functions.
-
-
class
ai.backend.client.session.
AsyncSession
(*, config=None)[source]¶ An API client session that makes API requests asynchronously using coroutines. You may call all function proxy methods like a coroutine. It provides an async context manager interface to ensure closing of the session upon errors and scope exits.
-
config
¶ The configuration used by this session object.
-
AgentWatcher
¶ The
AgentWatcher
function proxy bound to this session.
-
Auth
¶ The
Auth
function proxy bound to this session.
-
EtcdConfig
¶ The
EtcdConfig
function proxy bound to this session.
-
Group
¶ The
Group
function proxy bound to this session.
-
Image
¶ The
Image
function proxy bound to this session.
-
Resource
¶ The
Resource
function proxy bound to this session.
-
KeypairResourcePolicy
¶ The
KeypairResourcePolicy
function proxy bound to this session.
-
User
¶ The
User
function proxy bound to this session.
-
ScalingGroup
¶ The
ScalingGroup
function proxy bound to this session.
-