Python SDK#

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
import 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["verdict"], result["stdout"])  # AC hello

asyncio.run(main())

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

Errors#

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

try:
    await client.run("python", "...")
except RustboxAuthError:       pass  # 401/403 - check API key
except RustboxRateLimitError:  pass  # 429 - back off
except RustboxServerError:     pass  # 5xx - SDK already retried
except RustboxTimeoutError:    pass  # exceeded timeout_secs
except RustboxError:           pass  # other 4xx

Configuration#

Rustbox(
    api_key,
    base_url="https://rustbox.orkait.com",  # default
    timeout_secs=65.0,                          # default
    max_retries=2,                              # default
)

Async context manager#

async with Rustbox(api_key) as client:
    result = await client.run("python", "print(1)")
# Connection pool closed cleanly on exit.

Webhooks#

# Configure the webhook endpoint on the project in the dashboard first.
await client.submit(
    "python", "...",
    wait=False,
)

See Webhooks for HMAC verification.

Source#

github.com/orkait/rustbox-sdk/python