Skip to main content

porter-sandbox

Python SDK for the Porter Sandbox API.

Pre-release. Pilot for Porter's multi-language SDK rollout.

Install

pip install porter-sandbox

Usage

from porter_sandbox import Porter

with Porter() as porter:
    sb = porter.sandboxes.create(
        image="python:3.11-alpine",
        command=["python", "-c", "print('hi')"],
    )
    print(sb.logs())
    sb.terminate()

Set PORTER_SANDBOX_API_KEY in your environment. By default, the SDK connects to Porter's in-cluster sandbox API at http://sandbox-api.porter-sandbox-system.svc.cluster.local:8080. Override it with PORTER_SANDBOX_BASE_URL or by passing base_url.

Async

For async code (FastAPI handlers, concurrent sandbox fan-out, etc.) use AsyncPorter — same surface, awaitable methods:

import asyncio
from porter_sandbox import AsyncPorter

async def main():
    async with AsyncPorter() as porter:
        sb = await porter.sandboxes.create(image="python:3.11-alpine", command=["python", "-c", "print('hi')"])
        print(await sb.logs())
        await sb.terminate()

asyncio.run(main())

Async is also the right choice when launching many sandboxes in parallel:

async with AsyncPorter() as porter:
    results = await asyncio.gather(*[
        porter.sandboxes.create(image="python:3.11", command=cmd) for cmd in commands
    ])

Layout

  • porter_sandbox/porter.py, resource namespace modules like porter_sandbox/sandboxes.py, porter_sandbox/_client.py, _models.py, enums.py, _errors.py, resources/ — generated from the sandbox-api OpenAPI spec via the sdk-gen workspace. Do not edit by hand.
  • porter_sandbox/sandbox.py — hand-written rich sandbox handle used by the generated sandboxes namespace
  • porter_sandbox/_base_client.py / _async_base_client.py — hand-written sync and async HTTP transports
  • porter_sandbox/_config.py, _retries.py — hand-written runtime (env-var resolution, retry/backoff)

Development

pip install -e ".[dev]"
pytest
ruff check .
mypy

To pull in a fresh generation from the sdk-gen workspace:

./scripts/sync-generated.sh /path/to/workstation/code/sandbox/sdk-gen/out/python

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

porter_sandbox-0.1.32.tar.gz (57.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

porter_sandbox-0.1.32-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

Details for the file porter_sandbox-0.1.32.tar.gz.

File metadata

  • Download URL: porter_sandbox-0.1.32.tar.gz
  • Upload date:
  • Size: 57.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for porter_sandbox-0.1.32.tar.gz
Algorithm Hash digest
SHA256 17854985212127f3b1ed4dd6b48d89d1a5fd1ae9f1bbd378fba0e1e5a0f82cca
MD5 251f291ad625641daa7fdb38b70e69e8
BLAKE2b-256 2178998c48e3ae5a938f49a830eaadbdf7d9e4681034222c8c054e4398911d5c

See more details on using hashes here.

Provenance

The following attestation bundles were made for porter_sandbox-0.1.32.tar.gz:

Publisher: release.yml on porter-dev/porter-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file porter_sandbox-0.1.32-py3-none-any.whl.

File metadata

File hashes

Hashes for porter_sandbox-0.1.32-py3-none-any.whl
Algorithm Hash digest
SHA256 d163c93cee46ace7a73dcbd2604e2a05b6e4b1a88cdebdef0d076fcb6085dfad
MD5 d4ced84747fe5687bf5d059bc076d27f
BLAKE2b-256 3a0bd704062458d6fee1ce5c0270064a73df881bab7f541bc313e35ca4033854

See more details on using hashes here.

Provenance

The following attestation bundles were made for porter_sandbox-0.1.32-py3-none-any.whl:

Publisher: release.yml on porter-dev/porter-python-sdk

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.55

2 files

0.1.47

2 files

0.1.41

2 files

0.1.35

2 files

This release

0.1.32 This release

2 files

0.1.26

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page