Skip to main content

slothbox (Python SDK)

Official Python SDK for the Slothbox API — typed, sync and async, with retries, cursor pagination, lifecycle waiters, and a webhook verification toolkit. Feature parity with @slothbox/sdk is tracked in PARITY_CHECKLIST.md.

pip install slothbox

Requires Python 3.10+ and an org service-account API key (sk_…, API plan) from the Slothbox dashboard — the SDK identifies itself on every request and the API rejects SDK traffic on other credentials (see SDK identification).

Quickstart

from slothbox import Slothbox

client = Slothbox()  # reads SLOTHBOX_API_KEY; or Slothbox(api_key="sk_…")

orgs = client.organizations.list()
envs = client.environments.list(org_id)

# Safe launch: always sends an Idempotency-Key, then polls until `running`.
box = client.environments.launch_and_wait(org_id, {"templateId": template_id})
print(box.env_id, box.status)

Async is the same surface with await:

from slothbox import AsyncSlothbox

async with AsyncSlothbox() as client:
    box = await client.environments.launch_and_wait(org_id, {"templateId": template_id})

Request bodies accept either the typed models (slothbox.models) or plain dicts keyed by the wire (JSON) names, as above.

SDK identification

Every request carries an always-on identification header:

x-slothbox-sdk: slothbox-sdk-python/<version>

The API uses it to identify SDK traffic, which must authenticate with an org service-account key (API plan). SDK-identified requests on any other credential are rejected 403 with code sdk_requires_service_key, raised as PermissionDeniedError. Identification wins: the header is set as a client-level default (so it also covers direct calls through the client.generated escape hatch) and re-asserted on every request the wrapper sends, so it cannot be removed or overridden — not via RequestOptions(headers=…), not via httpx_args, and not via the generated with_headers().

Errors

Every non-2xx response raises a typed exception with the API's machine-readable code, the gateway request id, and validation issues:

from slothbox import ConflictError, RateLimitError

try:
    client.environments.launch(org_id, {"templateId": template_id})
except ConflictError as err:
    if err.code == "template_not_baked":
        client.templates.wait_until_baked(org_id, template_id)
except RateLimitError as err:
    print("retry after", err.retry_after, "s — request", err.request_id)

Retries

GET/HEAD/PUT/DELETE are retried on 429/5xx/network errors (3 retries by default) with capped full-jitter backoff; Retry-After is honored. POST and PATCH are never blind-retried — a duplicated launch provisions a second EC2 box — unless the request carries an Idempotency-Key (environments.launch(..., idempotency_key=…); launch_and_wait always sends one). Tune with Slothbox(max_retries=…) or per request via RequestOptions(max_retries=…).

Pagination

The audit and webhook-delivery lists are cursor-paginated; iterating a page walks every page:

for event in client.audit.list_org_events(org_id, limit=100):
    ...

page = client.webhooks.list_deliveries(org_id, endpoint_id)
while page.has_next_page():
    page = page.get_next_page()

(async for on the async client.)

Webhooks

Verify deliveries with the exact raw bytes you received:

from slothbox import parse_webhook_event, WebhookVerificationError

try:
    event = parse_webhook_event(raw_body, request_headers, endpoint_secret)
except WebhookVerificationError as err:
    return 400, err.code

if event["type"] == "environment.stopped":
    ...

The verifier implements Standard Webhooks v1 (HMAC-SHA256, secret rotation, ±300s replay window) and is tested against the same vector file as the API's signer and the TS SDK.

Architecture

Per ADR 0001: a pinned openapi-python-client generates the typed core (slothbox._generated — committed, httpx + attrs, regenerated deterministically by scripts/generate.sh and diff-checked in CI), and the hand-written slothbox package on top is the public compatibility surface. client.generated exposes the generated AuthenticatedClient as an escape hatch — note that the generated set_httpx_client() bypasses auth; pass transports via Slothbox(httpx_args=…) instead.

Development

python -m venv .venv && .venv/bin/pip install -e '.[dev]'
ruff check . && ruff format --check .   # lint
mypy                                     # strict on the wrapper
pytest                                   # 3.10+ supported
scripts/generate.sh                      # regen the core from openapi.json

Releases are automated — see RELEASING.md.

Metadata

Release files for slothbox 0.2.0

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

Source distribution (sdist)

Source distribution for slothbox 0.2.0
File Size Uploaded Provenance
slothbox-0.2.0.tar.gz 146.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for slothbox 0.2.0
File Interpreter ABI Platform
slothbox-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 506.6 kB

Release files / slothbox-0.2.0.tar.gz

Download URL slothbox-0.2.0.tar.gz
Size 146.7 kB
Tags Source
SHA-256 checksum
How to use checksums
be0f292e012cae86c5d4c31e1dfbda96c678bf225655bdd392c6b758853be7d8
BLAKE2b-256 checksum
How to use checksums
78db6205e0a3b742b2d170c66c85e665bea99aead6c5da0cf23a0be217e34420
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 10, 2026.

Transparency log

Release files / slothbox-0.2.0-py3-none-any.whl

Download URL slothbox-0.2.0-py3-none-any.whl
Size 359.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f632da9cf572e41e4c0a701dc58cd450c4ec53d6ad8dc633d8fba51e74b67997
BLAKE2b-256 checksum
How to use checksums
02abfa93a135e76cfc433a00b214ada9718821d84461d964ecee991eb189c14d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

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 Jun 10, 2026.

Transparency log

Security for slothbox 0.2.0

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 slothbox-0.2.0.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 Jun 10, 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.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files Full provenance

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