Python SDK#
Async client for the Rustbox judge API, built on httpx, fully typed. Python 3.10 or newer.
Async only. Every operation is a coroutine. Wrap calls in
asyncio.run()from sync code.
Install#
uv add rustboxQuickstart#
import asyncio
import os
from rustbox import Rustbox, Verdict
async def main() -> None:
async with Rustbox(os.environ["RUSTBOX_API_KEY"]) as client:
execution = await client.run("python", "print(6 * 7)")
if execution.result.verdict is Verdict.AC:
print(execution.output.stdout)
asyncio.run(main())run returns an Execution once the run has finished: status, result.verdict, result.exit_code, output.stdout, output.stderr, metrics and evidence. Missing values are None.
Judge against test cases#
from rustbox import JudgeCase
judged = await client.judge(
"python",
"a, b = map(int, input().split())\nprint(a + b)",
[JudgeCase(stdin="1 2", expected="3"), JudgeCase(stdin="2 2", expected="4")],
)
print(judged.all_passed, [case.verdict for case in judged.results])Queue now, read later#
import uuid
accepted = await client.submit("python", "print(1)", idempotency_key=str(uuid.uuid4()))
execution = await client.get_result(accepted.id)With an idempotency_key the submit is retried on transient failures; without one it is sent once.
Errors#
from rustbox import (
RustboxApiError,
RustboxAuthError,
RustboxRateLimitError,
RustboxServerError,
RustboxStillRunningError,
RustboxTimeoutError,
)
try:
await client.run("python", "...")
except RustboxAuthError:
... # 401/403: check the API key
except RustboxRateLimitError as error:
... # 429: wait error.retry_after_secs
except RustboxServerError:
... # 5xx after the SDK's retries
except RustboxTimeoutError:
... # a request timed out
except RustboxStillRunningError as error:
... # run used up its polling budget: get_result(error.run_id) later
except RustboxApiError as error:
... # other 4xx: error.status, error.messageEvery error derives from RustboxError; RustboxConfigError, RustboxTransportError and RustboxDecodeError complete the set.
Configuration#
Rustbox(
api_key,
region="in",
timeout_secs=65.0,
max_retries=2,
)base_url pins an exact endpoint. RUSTBOX_BASE_URL and RUSTBOX_REGION are read when the arguments are not given.
Webhooks#
Webhooks are set per project in the dashboard; submit needs nothing extra. See Webhooks for signature verification.