Skip to main content

prefect-aca-sessions

A Prefect worker that runs flow runs in Azure Container Apps dynamic sessions (code interpreter session pools). Worker type: azure-container-apps-sessions.

Status: unit-tested only. It has not yet been verified against a real session pool.

How it works

The worker is a long-running process that polls a Prefect work pool. For each flow run it:

  1. Authenticates to the pool's management endpoint with a Microsoft Entra token (DefaultAzureCredential, audience https://dynamicsessions.io).
  2. Starts prefect flow-run execute as a detached process inside a session (after pip install-ing pip_packages). The session identifier defaults to the flow run ID.
  3. Polls the session, forwards the process output to the flow run logs, and reports the exit code.
  4. Deletes the session (unless delete_session_on_completion is false).

A single /executions call is limited to 220 seconds, which is why the flow runs as a background process that is polled rather than inside one call.

Prerequisites

  • A self-hosted Prefect server reachable from both the worker and the sessions.
  • An Azure Container Apps code interpreter session pool (az containerapp sessionpool create --container-type PythonLTS ...). Note its pool management endpoint: az containerapp sessionpool show -n <pool> -g <rg> --query properties.poolManagementEndpoint -o tsv
  • An identity for the worker with the Azure ContainerApps Session Executor role on the pool.
  • Sessions with network egress to your Prefect API (the session pool's network status must be EgressEnabled) and to PyPI, or a pool with the packages you need already available.
  • Python 3.12+ and uv.

1. Install the worker

The package must be installed in the environment where prefect runs, because Prefect discovers worker types through the prefect.collections entry point.

uv pip install prefect-aca-sessions                               # or, from a checkout: uv pip install -e .
prefect worker start --help                                       # sanity check

2. Point the CLI at your server

export PREFECT_API_URL=https://prefect.example.com/api
# export PREFECT_API_KEY=...   # only if your server has basic auth / a gateway key

3. Create the work pool

prefect work-pool create aca-sessions --type azure-container-apps-sessions

The session pool endpoint can be set in three places. Each one overrides the ones after it:

  1. Per deployment, with the pool_management_endpoint job variable.
  2. As the pool default, in the UI (Work Pools → aca-sessions → Edit → Pool management endpoint).
  3. On the worker host, with the ACA_SESSIONS_POOL_MANAGEMENT_ENDPOINT environment variable (see step 5).

4. Authenticate the worker to Azure

DefaultAzureCredential is used, so any of these work:

  • Managed identity (worker on an Azure VM, ACA, AKS): assign the Session Executor role to it.
  • Service principal: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_CLIENT_SECRET.
  • Local development: az login.

5. Start the worker

export ACA_SESSIONS_POOL_MANAGEMENT_ENDPOINT=https://<region>.dynamicsessions.io/subscriptions/<sub>/resourceGroups/<rg>/sessionPools/<pool>
prefect worker start --pool aca-sessions --type azure-container-apps-sessions

Run it under a process manager (systemd, a container, etc.) for production.

6. Deploy a flow to the pool

from prefect import flow


@flow(log_prints=True)
def hello():
    print("running in an ACA session")


if __name__ == "__main__":
    hello.from_source(
        source="https://github.com/<you>/<repo>",
        entrypoint="flows.py:hello",
    ).deploy(
        name="hello-aca",
        work_pool_name="aca-sessions",
        job_variables={
            "pip_packages": ["prefect", "pandas"],
        },
    )

The session has to fetch the flow code itself (git source, or a pull step), because nothing is shared with the worker's filesystem. Add private-repo credentials via the deployment's pull steps and env.

Job variables

Variable Default Description
pool_management_endpoint $ACA_SESSIONS_POOL_MANAGEMENT_ENDPOINT on the worker Session pool management endpoint URL. A flow run fails if neither is set
api_version 2025-10-02-preview Sessions data-plane API version
session_identifier flow run ID Session to run in. A fixed value reuses one session across runs, so runs can see each other's files
pip_packages ["prefect"] Installed in the session before the run. Pin the Prefect version to match your server
poll_interval_seconds 10 Seconds between status polls
delete_session_on_completion true Delete the session after the run
env {} Extra environment variables for the flow run process
command prefect flow-run execute Command run in the session

Security notes

  • The flow run's environment (including PREFECT_API_URL and any PREFECT_API_KEY) is sent to the session inside the execution request. Use a dedicated, least-privilege API key.
  • Session identifiers are sensitive; don't share a fixed identifier across tenants.

Known limitations

  • Cancelling a flow run does not stop the process in the session (kill_infrastructure is not implemented); delete the session to stop it.
  • Session lifetime and idle limits are set on the pool and apply to long flow runs.

Development

uv sync
uv run pytest

Metadata

Release files for prefect-aca-sessions 1.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for prefect-aca-sessions 1.1.4
File Size Uploaded Provenance
prefect_aca_sessions-1.1.4.tar.gz 7.1 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for prefect-aca-sessions 1.1.4
File Interpreter ABI Platform
prefect_aca_sessions-1.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 16.4 kB

Release files / prefect_aca_sessions-1.1.4.tar.gz

Download URL prefect_aca_sessions-1.1.4.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
db309a01ea88f29c22ae6f6718bc732d19bbf2bfd40ec502dbb5ebf858799fa9
BLAKE2b-256 checksum
How to use checksums
9f3023a7a8efb6d44832c19d60a48505b1f97a6e66f983e9fc946040ec2566f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Release files / prefect_aca_sessions-1.1.4-py3-none-any.whl

Download URL prefect_aca_sessions-1.1.4-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d599dd52b962d901f2d3cfcd5a7ef32e1b37a2a277571efebe9d06c71eee32d7
BLAKE2b-256 checksum
How to use checksums
4b0134017a606de4e15e86c39104c9ed173e17a0c587e4a9c665ecbadbb0e021
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

Security for prefect-aca-sessions 1.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for prefect_aca_sessions-1.1.4.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 7, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page