Skip to main content

🐍 Rustbox Python SDK

PyPI version Python

Async-first via httpx. One required dep. Typed exceptions.

⚠️ Async-only. All public methods are coroutines. Wrap with asyncio.run() from sync code.

🚀 Install

pip install rustbox        # or: uv pip install rustbox / poetry add rustbox

⚡ Quickstart

import asyncio, os
from rustbox import Rustbox

async def main():
    client = Rustbox(os.environ["RUSTBOX_API_KEY"])
    result = await client.run(language="python", code="print('hello')")
    print(result["result"]["verdict"], result["output"]["stdout"])  # AC hello

asyncio.run(main())

run() submits, waits for sync completion, polls if needed, returns the verdict.

Response shape (schema v2)

{
  "id": "uuid",
  "schema_version": "2.0",
  "language": "python",
  "profile": "judge",
  "status": "completed",
  "timestamps": { "created_at": "...", "started_at": "...", "completed_at": "..." },
  "result": {
    "verdict": "AC",
    "cause": "normal_exit",
    "actor": "runtime",
    "exit_code": 0,
    "signal": null,
    "error_message": null
  },
  "output": { "stdout": "42\n", "stderr": "", "integrity": "complete" },
  "metrics": {
    "cpu_time_secs": 0.013,
    "wall_time_secs": 0.02,
    "memory_peak_bytes": 3715072,
    "cpu_wall_ratio": 0.65,
    "divergence": "cpu_bound"
  },
  "evidence": {
    "isolation": { "mode": "strict", "controls_applied": [], "controls_missing": [] },
    "limits": { "cgroup_backend": "cgroup_v2", "cgroup": { "memory_peak_bytes": 3715072, "oom_kill_events": 0 } },
    "teardown": { "reap_status": "clean", "zombie_count": 0, "cleanup_verified": true }
  }
}

verdict is one of AC | RE | TLE | MLE | PLE | FSE | SIG | IE. status is one of pending | running | completed | error. Read the verdict at result["result"]["verdict"], output at result["output"]["stdout"], and timing at result["metrics"]["cpu_time_secs"].

Profiles

# Judge profile (default) - short evaluation runs, no egress proxy.
await client.run("python", "print(1)")

# Agent profile - longer jobs, egress proxy on, per-key byte budget.
# Requires a non-trial API key.
await client.run("python", "...", profile="agent")

🔒 Errors

from rustbox import (
    RustboxAuthError, RustboxRateLimitError, RustboxServerError, RustboxError,
)

try:
    await client.run("python", "...")
except RustboxAuthError:       pass  # 401/403
except RustboxRateLimitError:  pass  # 429 - back off
except RustboxServerError:     pass  # 5xx - retry
except RustboxError:           pass  # other
🧰 Full API
Rustbox(
    api_key: str,
    base_url: str = DEFAULT_BASE_URL,
    *,
    timeout_secs: float = 65.0,
    max_retries: int = 2,
)

await client.run(
    language: str,
    code: str,
    stdin: str = "",
    profile: Literal["judge", "agent"] | None = None,
)  # -> dict

await client.submit(
    language, code, stdin="",
    profile=None, wait=False,
    idempotency_key=None,
)  # -> dict

await client.get_result(job_id)    # -> dict
await client.get_languages()       # -> list[str]
await client.get_health()          # -> dict
await client.get_ready()           # -> dict
await client.aclose()              # close httpx connection pool
🧪 Tests
cd python
uv pip install pytest pytest-asyncio respx httpx
python -m pytest -q

respx mocks httpx. No network.

🔗

Metadata

Release files for rustbox 0.4.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 rustbox 0.4.0
File Size Uploaded Provenance
rustbox-0.4.0.tar.gz 20.6 kB Without provenance Details

Built distribution (wheel)

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

Total release size: 28.7 kB

Release files / rustbox-0.4.0.tar.gz

Download URL rustbox-0.4.0.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
0aafe298d72ab543c20f38aec8860297b5df45a75a4199ed0a3edc54d457b0f4
BLAKE2b-256 checksum
How to use checksums
f7bd2115de2c9054f35697ecda901c9b91f782c828589d930b5544fc7ee11df0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / rustbox-0.4.0-py3-none-any.whl

Download URL rustbox-0.4.0-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f370e6c9f30f9dbcb29c59c953393f2f843fbb42b69cc42cb6d3c7144b90b07e
BLAKE2b-256 checksum
How to use checksums
9adf32b222ba98ea50d31c3ed3b409c88500b7cd11701107da55d8097cc08ca2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for rustbox 0.4.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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