Python SDK for the Porter Sandbox API
Project description
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 likeporter_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 generatedsandboxesnamespaceporter_sandbox/_base_client.py/_async_base_client.py— hand-written sync and async HTTP transportsporter_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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file porter_sandbox-0.1.26.tar.gz.
File metadata
- Download URL: porter_sandbox-0.1.26.tar.gz
- Upload date:
- Size: 57.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b8910775115130b7f4a3e4e906e49ba8c60f9555ccec4ddda1e202967122b710
|
|
| MD5 |
713094fb8a7484d695665c2b1e3e02ff
|
|
| BLAKE2b-256 |
9baa819c32e98bbf365ba3b7f7cb52fac737c20279a05f50672a3ed90ef01a09
|
Provenance
The following attestation bundles were made for porter_sandbox-0.1.26.tar.gz:
Publisher:
release.yml on porter-dev/porter-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
porter_sandbox-0.1.26.tar.gz -
Subject digest:
b8910775115130b7f4a3e4e906e49ba8c60f9555ccec4ddda1e202967122b710 - Sigstore transparency entry: 1916490442
- Sigstore integration time:
-
Permalink:
porter-dev/porter-python-sdk@97906b2a96b4e77847c3a1efb2437ced82976ca8 -
Branch / Tag:
refs/tags/v0.1.26 - Owner: https://github.com/porter-dev
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@97906b2a96b4e77847c3a1efb2437ced82976ca8 -
Trigger Event:
release
-
Statement type:
File details
Details for the file porter_sandbox-0.1.26-py3-none-any.whl.
File metadata
- Download URL: porter_sandbox-0.1.26-py3-none-any.whl
- Upload date:
- Size: 22.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18ee28c488f3ce955198c43ee54d8f7047d2672a310ba94d3cde52f8ea31ad3b
|
|
| MD5 |
f2d71eb1958cf55f2a016dd821aa135b
|
|
| BLAKE2b-256 |
56bf8ee2fcfcfdc1bd7f0f6bf88d2b8cede8ec531fa318fd7277b11df8c6ef3e
|
Provenance
The following attestation bundles were made for porter_sandbox-0.1.26-py3-none-any.whl:
Publisher:
release.yml on porter-dev/porter-python-sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
porter_sandbox-0.1.26-py3-none-any.whl -
Subject digest:
18ee28c488f3ce955198c43ee54d8f7047d2672a310ba94d3cde52f8ea31ad3b - Sigstore transparency entry: 1916490605
- Sigstore integration time:
-
Permalink:
porter-dev/porter-python-sdk@97906b2a96b4e77847c3a1efb2437ced82976ca8 -
Branch / Tag:
refs/tags/v0.1.26 - Owner: https://github.com/porter-dev
-
Access:
internal
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@97906b2a96b4e77847c3a1efb2437ced82976ca8 -
Trigger Event:
release
-
Statement type: