Platinum Python SDK — client for hardware-isolated sandbox microVMs.
Project description
platinum-sdk (Python)
Python client for Platinum — hardware-isolated sandbox microVMs (one Cloud Hypervisor VM per sandbox, sub-second boots via a warm pool).
pip install platinum-sdk # import name: platinum
Python ≥ 3.9, typed (PEP 561 — ships py.typed; mypy --strict clean). Sync and async clients. Server-side use only — never ship an API key into client-side code.
Quickstart
from platinum import Platinum
dn = Platinum(token="pt_live_...", api_url="https://api.platinum.dev")
# or: PT_TOKEN / PT_API_URL env vars
# Pick a template that exists on YOUR deployment first:
print(dn.templates.list())
sbx = dn.sandboxes.create(template="pt-base", wait_for_running=True)
r = sbx.exec(["uname", "-a"]).check() # .check() raises on non-zero exit
print(r.stdout)
sbx.delete()
Async — a full 1:1 mirror of the sync surface:
from platinum import AsyncPlatinum
async with AsyncPlatinum(token="pt_live_...", api_url="https://api.platinum.dev") as dn:
sbx = await dn.sandboxes.create(template="pt-base", wait_for_running=True)
r = await sbx.exec("uname -a") # argv list or plain string
print(r.stdout)
await sbx.delete()
Expose a port at create time (URL comes back in the same response):
sbx = dn.sandboxes.create(
template="pt-base",
expose=[{"port": 8080, "public": True}],
wait_for_running=True,
)
print(sbx.exposed_url(8080))
Build a custom image inline (cache-hit on repeat, built on first use):
from platinum import Platinum, Template
dn = Platinum()
image = (Template.from_python_image("3.12-slim")
.pip_install(["fastapi", "uvicorn"])
.workdir("/app"))
sbx = dn.sandboxes.create(image=image, wait_for_running=True, wait_timeout_ms=600_000)
Configuration
| Arg / env | Default | Meaning |
|---|---|---|
token / PT_TOKEN |
— (required) | API key pt_live_…, org-scoped bearer token |
api_url / PT_API_URL |
http://127.0.0.1:3000 |
Control-plane URL |
timeout |
60.0 |
Per-request timeout in seconds (file transfer calls override per call) |
transport |
— | httpx transport override (e.g. httpx.MockTransport in tests) |
Errors
Everything the SDK raises extends PlatinumError (.status, .body, .code — the
API's machine-readable error code, also folded into str(err)):
from platinum import NotFoundError, ConflictError, RateLimitError
try:
sbx.exec("true")
except NotFoundError: # sandbox gone
...
except ConflictError as e: # e.g. e.code == "sandbox_not_running"
...
except RateLimitError as e: # back off e.retry_after_seconds — the SDK never retries
...
Subclasses: ValidationError (400) · AuthenticationError (401) · ForbiddenError (403)
· NotFoundError (404) · ConflictError (409) · RateLimitError (429) · ServerError
(5xx) · PlatinumTimeoutError / PlatinumConnectionError (client-side, status == 0).
No automatic retries, ever — a 429 or a failed create is surfaced, never silently retried.
Surface (at parity with the TypeScript SDK)
The two SDKs expose the same operations — enforced in CI by verify/sdk-parity.sh
(name-level) and the offline unit suites (behaviour). The async client mirrors the sync
surface 1:1 (enforced by tests/test_unit.py::test_async_mirrors_sync_surface).
| Area | Methods |
|---|---|
| Sandboxes | sandboxes.create(...) · get · connect · list · iter (auto-pagination) · rename · delete |
| Lifecycle | stop/start (optional server-side wait) · pause/resume · kill · resize · fork · clone · snapshot · list_snapshots · delete_snapshot · restore · restore_from_backup · archive · backup · wait_running · wait_state · refresh |
| Run | exec(argv | str) · sh(script) · run_code(code, lang=None) — defaults to the sandbox's create-time language |
| Files (vsock) | files.read/write/delete/list/stat/mkdir/exists · find (glob) · grep (content) · replace (bulk sed) · watch (generator of change events) |
| Networking | expose(port, public=, ttl_seconds=) · unexpose · exposed_url · revoke_expose_token · set_egress_policy · add_ssh_keys |
| Observability | metrics() (live cpu/mem/disk) · usage() (billed usage) |
| Platform | templates.list/get/delete · Template builder · webhooks.* · volumes.* · regions.list() · me() · health.check() |
| Results | ExecResult(stdout, stderr, exit_code, duration_ms, lang) with .check() |
Watch for file changes:
for ev in sbx.files.watch("/workspace", max_seconds=60):
if ev["event"] == "change":
print(ev["data"]["type"], ev["data"]["path"])
Not wrapped yet: interactive terminal (WebSocket), cross-host migrate (admin-only),
API-key management, audit-log queries, billing.
Limits worth knowing
files.writebodies must stay ≤ 16 MiB — larger writes currently truncate and fail through the vsock path. Split big files into ≤ 16 MiB chunks, or fetch them directly inside the sandbox (execwithwget).exec/run_codeare buffered, not streaming — output arrives after the command exits (default timeout 30 s viatimeout_ms).run_codesource is capped at 1 MiB.- Template names and minimums are per-deployment.
pt-base(busybox — no git/pip/node/httpdinside;nc/wgetavailable) exists on default installs; hosted deployments may only offer other templates with higher cpu/ram minimums. Calltemplates.list()first; a below-minimum create fails with a clear 400. - Background processes are reaped when their
execcall returns. To leave a server running, daemonize it:setsid sh -c '<server loop>' >/dev/null 2>&1 < /dev/null &— seeexamples/02_expose_service.py.
Testing
pip install -e '.[test]' && pytest runs the offline unit suite (httpx.MockTransport,
no network). The live e2e is opt-in: PT_E2E=1 PT_API_URL=… PT_TOKEN=… pytest test_e2e.py.
Examples
Runnable scripts in examples/:
pip install platinum-sdk
PT_API_URL=… PT_TOKEN=… python packages/sdk-py/examples/01_create_exec_delete.py
License
MIT
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 platinum_sdk-0.3.0.tar.gz.
File metadata
- Download URL: platinum_sdk-0.3.0.tar.gz
- Upload date:
- Size: 31.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 |
270393c99362955d02ff5fbd7745c3d6866d5b637e0f02ea04ee329533e5eb0b
|
|
| MD5 |
b526108ea6ee235d694c12412785fc9c
|
|
| BLAKE2b-256 |
b401a13dcc9b3b9abb6083679f1645e81bbf8d4e0ce7338b7d748b39fd5dd2ec
|
Provenance
The following attestation bundles were made for platinum_sdk-0.3.0.tar.gz:
Publisher:
release-sdks.yml on kortix-ai/platinum
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
platinum_sdk-0.3.0.tar.gz -
Subject digest:
270393c99362955d02ff5fbd7745c3d6866d5b637e0f02ea04ee329533e5eb0b - Sigstore transparency entry: 2199506389
- Sigstore integration time:
-
Permalink:
kortix-ai/platinum@580a08e3bf4eabeff6847f53789057a5d9e35d00 -
Branch / Tag:
refs/tags/platinum-sdk-py-v0.3.0 - Owner: https://github.com/kortix-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-sdks.yml@580a08e3bf4eabeff6847f53789057a5d9e35d00 -
Trigger Event:
push
-
Statement type:
File details
Details for the file platinum_sdk-0.3.0-py3-none-any.whl.
File metadata
- Download URL: platinum_sdk-0.3.0-py3-none-any.whl
- Upload date:
- Size: 25.5 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 |
62bf554b81ccb95140aacd0a68519ec64b3e480f2526b36fe11a59eb1cbc351d
|
|
| MD5 |
53ae74a8be35ec78d71f10c9a0d2f816
|
|
| BLAKE2b-256 |
96993be2a42d6f36431ee13c30ae5b9be6ba849ac6c5a1ed73a6cd519035c64e
|
Provenance
The following attestation bundles were made for platinum_sdk-0.3.0-py3-none-any.whl:
Publisher:
release-sdks.yml on kortix-ai/platinum
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
platinum_sdk-0.3.0-py3-none-any.whl -
Subject digest:
62bf554b81ccb95140aacd0a68519ec64b3e480f2526b36fe11a59eb1cbc351d - Sigstore transparency entry: 2199506474
- Sigstore integration time:
-
Permalink:
kortix-ai/platinum@580a08e3bf4eabeff6847f53789057a5d9e35d00 -
Branch / Tag:
refs/tags/platinum-sdk-py-v0.3.0 - Owner: https://github.com/kortix-ai
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-sdks.yml@580a08e3bf4eabeff6847f53789057a5d9e35d00 -
Trigger Event:
push
-
Statement type: