Share via


SessionsPythonTool Class

A plugin for running Python code in an Azure Container Apps dynamic sessions code interpreter.

Initializes a new instance of the SessionsPythonTool class.

Constructor

SessionsPythonTool(auth_callback: Callable[[...], Any | Awaitable[Any]] | None = None, pool_management_endpoint: str | None = None, settings: SessionsPythonSettings | None = None, http_client: AsyncClient | None = None, env_file_path: str | None = None, token_endpoint: str | None = None)

Parameters

Name Description
auth_callback
Default value: None
pool_management_endpoint
Default value: None
settings
Default value: None
http_client
Default value: None
env_file_path
Default value: None
token_endpoint
Default value: None

Methods

download_file

Download a file from the session pool.

execute_code

Executes the provided Python code.

list_files

List the files in the session pool.

upload_file

Upload a file to the session pool.

download_file

Download a file from the session pool.

async download_file(*, remote_file_name: Annotated[str, 'The name of the file to download, relative to /mnt/data'], local_file_path: Annotated[str | None, 'The local file path to save the file to, optional'] = None) -> Annotated[BytesIO | None, 'The data of the downloaded file']

Parameters

Name Description
remote_file_name
Required

The name of the file to download, relative to /mnt/data.

local_file_path
Required

The path to save the downloaded file to. Should include the extension. If not provided, the file is returned as a BufferedReader.

Keyword-Only Parameters

Name Description
remote_file_name
Required
local_file_path
Required

Returns

Type Description
<xref:BufferedReader>

The data of the downloaded file.

execute_code

Executes the provided Python code.

async execute_code(code: Annotated[str, 'The valid Python code to execute']) -> str

Parameters

Name Description
code
Required
str

The valid Python code to execute

Returns

Type Description
str

The result of the Python code execution in the form of Result, Stdout, and Stderr

Exceptions

Type Description

If the provided code is empty.

list_files

List the files in the session pool.

async list_files() -> list[SessionsRemoteFileMetadata]

Returns

Type Description

The metadata for the files in the session pool

upload_file

Upload a file to the session pool.

async upload_file(*, local_file_path: Annotated[str, 'The path to the local file on the machine'], remote_file_path: Annotated[str | None, 'The remote path to the file in the session. Defaults to /mnt/data'] = None) -> Annotated[SessionsRemoteFileMetadata, 'The metadata of the uploaded file']

Parameters

Name Description
remote_file_path
Required
str

The path to the file in the session.

local_file_path
Required
str

The path to the file on the local machine.

Keyword-Only Parameters

Name Description
local_file_path
Required
remote_file_path
Required

Returns

Type Description
<xref:RemoteFileMetadata>

The metadata of the uploaded file.

Exceptions

Type Description

If local_file_path is not provided.

Attributes

auth_callback

auth_callback: Callable[[...], Any | Awaitable[Any]]

http_client

http_client: AsyncClient

pool_management_endpoint

pool_management_endpoint: Annotated[Url, UrlConstraints(max_length=2083, allowed_schemes=['https'], host_required=None, default_host=None, default_port=None, default_path=None)]

settings

settings: SessionsPythonSettings