Overview
The Judge0 Python SDK has two layers:
a high-level API that creates submissions, expands test cases, batches requests, and optionally waits for results;
a low-level API on
Clientthat maps one-to-one to Judge0 HTTP routes.
Most applications should start with judge0.run(). Use the client methods
when you need a single HTTP call, custom polling, or server metadata.
High-level and low-level API
High-level functions live in judge0.api. The entry-point functions
(judge0.run(), judge0.async_run(), judge0.wait(), and
judge0.get_client()) are re-exported from the judge0 package.
They accept either source code, a
Submission, or a sequence of submissions. If you
omit client, the SDK resolves one from the environment. See
Client Resolution.
Function |
Role |
|---|---|
|
Create submission(s) and wait until they finish. These names are aliases
of |
|
Create submission(s) and return immediately. These are not
|
|
Poll existing submission(s) until they finish or the retry strategy stops. |
|
Resolve the implicit client for CE ( |
Send already-built submissions, splitting them into batches that fit the server limit. |
|
Refresh status and result fields on existing submissions. |
|
Expand one or more submissions across test cases. Used internally by
|
The low-level API is the methods on Client:
Low-level calls do not wait for execution, do not expand test cases, and do
not pick a client for you. create_submissions and get_submissions on
the client cannot send more items than
client.config.max_submission_batch_size. The high-level helpers batch
automatically.
async_run versus run
judge0.run() blocks until Judge0 reports a terminal status or the
client’s retry strategy is exhausted, which may return a queued or processing
submission.
judge0.async_run() only creates the submission(s) and returns the
submission objects with their token fields populated.
Call judge0.wait() later, or poll with
judge0.api.get_submissions().
import judge0
submission = judge0.async_run(source_code="print('hello, world')")
print(submission.stdout) # None; the job is not finished yet.
judge0.wait(submissions=submission)
print(submission.stdout) # hello, world
Important classes
Client: HTTP client for one Judge0 server. Provider subclasses includeJudge0CloudCE,RapidJudge0CE, andATDJudge0CE, plus the Extra CE variants.Submission: request and response for one program run. Setsource_code,language,stdin, and optional limits before sending. After execution, readstdout,stderr,status,time, andmemory.TestCase: pair ofinputandexpected_output.judge0.run()also accepts tuples, lists, and dicts and normalizes them to this type.LanguageAliasandFlavor: language aliases such asjudge0.PYTHONorjudge0.C, and the CE / Extra CE flavors used for client resolution.Status: submission status, includingAccepted, compile errors, and runtime errors.FileandFilesystem: extra files sent with a submission, or files produced after execution.RegularPeriodRetry,MaxRetries, andMaxWaitTime: polling strategies used byjudge0.wait().
Typical flow
Build source code or a
Submission.Optionally attach test cases or extra files.
Call
judge0.run(), orjudge0.async_run()plusjudge0.wait().Inspect
stdout,status, and other result fields.
import judge0
result = judge0.run(
source_code="print(f'Hello, {input()}!')",
language=judge0.PYTHON,
test_cases=[
("Ada", "Hello, Ada!"),
{"input": "Bob", "expected_output": "Hello, Bob!"},
],
)
for case in result:
print(case.status, case.stdout)
Pass an explicit client when you do not want implicit resolution:
import judge0
client = judge0.RapidJudge0CE(api_key="xxx")
result = judge0.run(client=client, source_code="print(42)")
print(result.stdout)
For the full parameter lists, see the API Module reference, the Clients Module reference, and the Submission Module reference.