Kernel Functions

class ai.backend.client.kernel.Kernel(kernel_id, owner_access_key=None)[source]

Provides various interactions with compute sessions in Backend.AI.

The term ‘kernel’ is now deprecated and we prefer ‘compute sessions’. However, for historical reasons and to avoid confusion with client sessions, we keep the backward compatibility with the naming of this API function class.

For multi-container sessions, all methods take effects to the master container only, except destroy() and restart() methods. So it is the user’s responsibility to distribute uploaded files to multiple containers using explicit copies or virtual folders which are commonly mounted to all containers belonging to the same compute session.

session = None

The client session instance that this function class is bound to.


Opens a pseudo-terminal of the kernel (if supported) streamed via websockets.

Return type



a StreamPty object.

stream_execute(code='', *, mode='query', opts=None)[source]

Executes a code snippet in the streaming mode. Since the returned websocket represents a run loop, there is no need to specify run_id explicitly.

Return type


class ai.backend.client.kernel.StreamPty(session, underlying_ws)[source]

A derivative class of WebSocketResponse which provides additional functions to control the terminal.