Simple Judge0 client for Python
Project description
Judge0 Client
Asynchronous Python client for the Judge0 API. Built on top of httpx with Pydantic models for requests and responses.
This library helps you submit code to a Judge0 instance and retrieve execution results with clear, typed models and convenient error handling.
Highlights
- Async,
httpx-based client - Pydantic models for request/response validation
- Single-file and multi-file submissions
- Fully automated Base64 handling for text fields and additional files
- Token-based auth header support
Requirements
- Python 3.10+
- A running Judge0 instance (public or self-hosted)
Installation
From PyPI:
pip install judge0-client
or
uv add judge0-client
Quick Start (async)
import asyncio
from judge0_client import Judge0Client, SingleFileSubmission
async def main() -> None:
# On many instances, language_id=71 corresponds to Python 3
req = SingleFileSubmission(
language_id=71,
source_code='print("Hello, Judge0!")',
)
async with Judge0Client(base_url="https://YOUR_JUDGE0_URL.com") as client:
# 1) Create submission — returns token
created = await client.create_submission(req)
# 2) Poll result by token
detail = await client.get_submission(created.token)
print("STATUS:", detail.status.description)
print("STDOUT:", detail.stdout)
if __name__ == "__main__":
asyncio.run(main())
Documentation
Usage
Client parameters
Judge0Client(
base_url: str, # Base URL of your Judge0 instance (no trailing slash)
timeout: float | httpx.Timeout = 10.0,
auth_header: str = "X-Auth-Token", # Custom auth header name if needed
auth_token: str | SecretStr | None = None, # Token value passed in the auth header
)
Notes:
- The client sets
Accept: application/jsonandContent-Type: application/jsonheaders. - If
auth_tokenis provided, it will be sent as{auth_header}: <token>.
Single-file submissions
from judge0_client import SingleFileSubmission
req = SingleFileSubmission(
language_id=71,
source_code="print('sum =', int(input()) + 2)",
stdin="40\n",
)
# Then use it with the client as shown in the Quick Start.
You can attach additional files that will be zipped and Base64-encoded automatically:
from judge0_client import SingleFileSubmission
req = SingleFileSubmission(
language_id=71,
source_code="import helper; print(helper.answer())",
additional_files={
"helper.py": "def answer():\n return 42\n",
},
)
Multi-file submissions
Use MultiFileSubmission (language id=89 on Judge0 for multi-file/script-based runs). You must provide a run script in additional_files.
from judge0_client import MultiFileSubmission
req = MultiFileSubmission(
# language_id is fixed to 89 in this model
additional_files={
# Required run script
"run": "python main.py\n",
# Your sources
"main.py": "print('Hello from multi-file!')\n",
},
)
# Then use it with the client as shown in the Quick Start.
Error handling
Network or HTTP errors raise Judge0Error with helpful context:
import asyncio
from judge0_client import Judge0Client, SingleFileSubmission, Judge0Error
async def main() -> None:
try:
async with Judge0Client(base_url="https://judge0.ce.pdn.ac.lk") as client:
req = SingleFileSubmission(language_id=71, source_code="print('hi')")
created = await client.create_submission(req)
detail = await client.get_submission(created.token)
print(detail.stdout)
except Judge0Error as e:
# Inspect message, status code, and response body (if any)
print("Submission failed:", e)
if __name__ == "__main__":
asyncio.run(main())
Tips
- Language IDs differ across Judge0 instances. Check your instance’s languages endpoint to confirm IDs.
- The client and models automatically handle Base64 encoding for text fields (
source_code,stdin,expected_output) and additional files when required by Judge0.
Contributing
Contributions are welcome! Feel free to open an issue or a pull request.
License
MIT License — see LICENSE.
Project details
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 judge0_client-0.3.0.tar.gz.
File metadata
- Download URL: judge0_client-0.3.0.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76ac2887c1bc5ce687a408ba18288ad349c6f1395d3b726fe6a04948395f7cea
|
|
| MD5 |
f8b89588c7072903865b87aeb9f327be
|
|
| BLAKE2b-256 |
41aa272077cba5abad9190254dbbf1bf67a6ae7907116bf91b45745da4703181
|
Provenance
The following attestation bundles were made for judge0_client-0.3.0.tar.gz:
Publisher:
build_and_release.yml on Roslovets-Inc/judge0-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
judge0_client-0.3.0.tar.gz -
Subject digest:
76ac2887c1bc5ce687a408ba18288ad349c6f1395d3b726fe6a04948395f7cea - Sigstore transparency entry: 740254011
- Sigstore integration time:
-
Permalink:
Roslovets-Inc/judge0-client@45957ced5f979f5545def9d90535408d620296df -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Roslovets-Inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_and_release.yml@45957ced5f979f5545def9d90535408d620296df -
Trigger Event:
push
-
Statement type:
File details
Details for the file judge0_client-0.3.0-py3-none-any.whl.
File metadata
- Download URL: judge0_client-0.3.0-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d7035efaf7e4ed30e0126292fde83b84d07ca7a90d3df94f859cb302e1225bac
|
|
| MD5 |
55b5086211e5cdcefc8f0220c50ea884
|
|
| BLAKE2b-256 |
3d054be68cc2053dcc37d04b46538872348463b250b0a7944b820854bd887fef
|
Provenance
The following attestation bundles were made for judge0_client-0.3.0-py3-none-any.whl:
Publisher:
build_and_release.yml on Roslovets-Inc/judge0-client
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
judge0_client-0.3.0-py3-none-any.whl -
Subject digest:
d7035efaf7e4ed30e0126292fde83b84d07ca7a90d3df94f859cb302e1225bac - Sigstore transparency entry: 740254020
- Sigstore integration time:
-
Permalink:
Roslovets-Inc/judge0-client@45957ced5f979f5545def9d90535408d620296df -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Roslovets-Inc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build_and_release.yml@45957ced5f979f5545def9d90535408d620296df -
Trigger Event:
push
-
Statement type: