API Reference

judge0_client

Judge0 client package.

Provides Judge0Client for interacting with the Judge0 API
and Pydantic models for requests and responses.

Judge0Client

Asynchronous client for the Judge0 API.

Source code in src/judge0_client/client.py
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
class Judge0Client:
    """Asynchronous client for the Judge0 API."""

    base_url: str
    timeout: float | httpx.Timeout
    _auth_header: str
    _auth_token: SecretStr | None
    _verify_certs: bool
    _client: httpx.AsyncClient | None

    def __init__(
            self,
            base_url: str,
            timeout: float | httpx.Timeout = 10.0,
            auth_header: str = "X-Auth-Token",
            auth_token: str | SecretStr | None = None,
            verify_certs: bool = True,
    ) -> None:
        self.base_url = base_url.rstrip("/")
        self.timeout = timeout
        self._auth_header = auth_header
        if isinstance(auth_token, SecretStr):
            self._auth_token = auth_token
        else:
            self._auth_token = SecretStr(auth_token) if auth_token else None
        self._verify_certs = verify_certs
        self._client = None

    async def __aenter__(self) -> Self:
        self.open()
        return self

    async def __aexit__(self, exc_type, exc, tb) -> None:  # noqa: ANN001
        await self.aclose()

    def open(self) -> None:
        """Initialize the underlying httpx client."""
        headers: dict[str, str] = ({
            "Accept": "application/json",
            "Content-Type": "application/json",
        }) | ({
                  self._auth_header: self._auth_token.get_secret_value()
              } if self._auth_token else {})
        if self._client is None:
            self._client = httpx.AsyncClient(
                base_url=self.base_url,
                timeout=self.timeout,
                headers=headers,
                verify=self._verify_certs,
            )

    async def aclose(self) -> None:
        if self._client:
            await self._client.aclose()
            self._client = None

    @property
    def client(self) -> httpx.AsyncClient:
        if self._client is None:
            raise RuntimeError("Client is not initialized. Use 'async with' or call open().")
        return self._client

    async def create_submission(
            self,
            request: BaseSubmission,
    ) -> SubmissionResponse:
        """Create a submission."""

        resp = await self.client.post(
            "/submissions",
            params={"base64_encoded": "true"},
            json=request.to_body(),
        )
        raise_for_status(resp)
        return SubmissionResponse.from_response(resp)

    async def get_submission(
            self,
            token: str,
    ) -> SubmissionDetail:
        """Get submission result by token."""

        resp = await self.client.get(
            url=f"/submissions/{token}",
            params={"base64_encoded": "true"}
        )
        raise_for_status(resp)
        return SubmissionDetail.from_response(resp).decode_base64()

    async def get_workers(self) -> list[WorkersResponse]:
        """Health-check endpoint: returns workers/queues state."""
        resp = await self.client.get("/workers")
        raise_for_status(resp)
        return WorkersResponse.from_response_list(resp)

    async def get_about(self) -> AboutResponse:
        """Returns general information."""
        resp = await self.client.get("/about")
        raise_for_status(resp)
        return AboutResponse.from_response(resp)

    async def get_isolate(self) -> str:
        """Returns result of isolate --version."""
        resp = await self.client.get("/isolate")
        raise_for_status(resp)
        return resp.text

    async def get_license(self) -> str:
        """Returns a license."""
        resp = await self.client.get("/license")
        raise_for_status(resp)
        return resp.text

open

open()

Initialize the underlying httpx client.

Source code in src/judge0_client/client.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def open(self) -> None:
    """Initialize the underlying httpx client."""
    headers: dict[str, str] = ({
        "Accept": "application/json",
        "Content-Type": "application/json",
    }) | ({
              self._auth_header: self._auth_token.get_secret_value()
          } if self._auth_token else {})
    if self._client is None:
        self._client = httpx.AsyncClient(
            base_url=self.base_url,
            timeout=self.timeout,
            headers=headers,
            verify=self._verify_certs,
        )

create_submission async

create_submission(request)

Create a submission.

Source code in src/judge0_client/client.py
74
75
76
77
78
79
80
81
82
83
84
85
86
async def create_submission(
        self,
        request: BaseSubmission,
) -> SubmissionResponse:
    """Create a submission."""

    resp = await self.client.post(
        "/submissions",
        params={"base64_encoded": "true"},
        json=request.to_body(),
    )
    raise_for_status(resp)
    return SubmissionResponse.from_response(resp)

get_submission async

get_submission(token)

Get submission result by token.

Source code in src/judge0_client/client.py
88
89
90
91
92
93
94
95
96
97
98
99
async def get_submission(
        self,
        token: str,
) -> SubmissionDetail:
    """Get submission result by token."""

    resp = await self.client.get(
        url=f"/submissions/{token}",
        params={"base64_encoded": "true"}
    )
    raise_for_status(resp)
    return SubmissionDetail.from_response(resp).decode_base64()

get_workers async

get_workers()

Health-check endpoint: returns workers/queues state.

Source code in src/judge0_client/client.py
101
102
103
104
105
async def get_workers(self) -> list[WorkersResponse]:
    """Health-check endpoint: returns workers/queues state."""
    resp = await self.client.get("/workers")
    raise_for_status(resp)
    return WorkersResponse.from_response_list(resp)

get_about async

get_about()

Returns general information.

Source code in src/judge0_client/client.py
107
108
109
110
111
async def get_about(self) -> AboutResponse:
    """Returns general information."""
    resp = await self.client.get("/about")
    raise_for_status(resp)
    return AboutResponse.from_response(resp)

get_isolate async

get_isolate()

Returns result of isolate --version.

Source code in src/judge0_client/client.py
113
114
115
116
117
async def get_isolate(self) -> str:
    """Returns result of isolate --version."""
    resp = await self.client.get("/isolate")
    raise_for_status(resp)
    return resp.text

get_license async

get_license()

Returns a license.

Source code in src/judge0_client/client.py
119
120
121
122
123
async def get_license(self) -> str:
    """Returns a license."""
    resp = await self.client.get("/license")
    raise_for_status(resp)
    return resp.text

Judge0Error

Bases: Exception

Generic Judge0 client exception.

Source code in src/judge0_client/utils/exceptions.py
5
6
class Judge0Error(Exception):
    """Generic Judge0 client exception."""

BaseSubmission pydantic-model

Bases: BaseModel, ABC

Request model for creating a submission in Judge0.

Fields:

Source code in src/judge0_client/models/base_submission.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
class BaseSubmission(BaseModel, ABC):
    """Request model for creating a submission in Judge0."""

    compiler_options: str | None = Field(
        default=None, description="Options for the compiler (i.e. compiler flags)", max_length=512
    )
    command_line_arguments: str | None = Field(
        default=None, description="Command line arguments for the program", max_length=512
    )
    stdin: str | None = Field(default=None, description="Input for program")
    expected_output: str | None = Field(
        default=None, description="Expected output of program. Used when you want to compare with stdout"
    )
    cpu_time_limit: float | None = Field(
        default=None, description="Default runtime limit for every program (seconds)"
    )
    cpu_extra_time: float | None = Field(
        default=None,
        description="When a time limit is exceeded, wait for extra time, before killing the program (seconds)"
    )
    wall_time_limit: float | None = Field(
        default=None, description="Limit wall-clock time in seconds (seconds)"
    )
    memory_limit: float | None = Field(default=None, description="Limit address space of the program (kilobytes)")
    stack_limit: int | None = Field(default=None, description="Limit process stack (kilobytes)")
    max_processes_and_or_threads: int | None = Field(
        default=None, description="Maximum number of processes and/or threads program can create"
    )
    enable_per_process_and_thread_time_limit: bool | None = Field(
        default=None, description="If true then cpu_time_limit will be used as per process and thread"
    )
    enable_per_process_and_thread_memory_limit: bool | None = Field(
        default=None, description="If true then memory_limit will be used as per process and thread"
    )
    max_file_size: int | None = Field(
        default=None, description="Limit file size created or modified by the program (kilobytes)"
    )
    redirect_stderr_to_stdout: bool | None = Field(
        default=None, description="If true standard error will be redirected to standard output"
    )
    enable_network: bool | None = Field(default=None, description="	If true program will have network access")
    number_of_runs: int | None = Field(
        default=None, description="Run each program number_of_runs times and take average of time and memory"
    )
    callback_url: str | None = Field(
        default=None,
        description="URL on which Judge0 will issue PUT request with the submission in a request body after submission has been done"
    )

    @abstractmethod
    def to_body(self) -> dict[str, Any]:
        pass

compiler_options pydantic-field

compiler_options = None

Options for the compiler (i.e. compiler flags)

command_line_arguments pydantic-field

command_line_arguments = None

Command line arguments for the program

stdin pydantic-field

stdin = None

Input for program

expected_output pydantic-field

expected_output = None

Expected output of program. Used when you want to compare with stdout

cpu_time_limit pydantic-field

cpu_time_limit = None

Default runtime limit for every program (seconds)

cpu_extra_time pydantic-field

cpu_extra_time = None

When a time limit is exceeded, wait for extra time, before killing the program (seconds)

wall_time_limit pydantic-field

wall_time_limit = None

Limit wall-clock time in seconds (seconds)

memory_limit pydantic-field

memory_limit = None

Limit address space of the program (kilobytes)

stack_limit pydantic-field

stack_limit = None

Limit process stack (kilobytes)

max_processes_and_or_threads pydantic-field

max_processes_and_or_threads = None

Maximum number of processes and/or threads program can create

enable_per_process_and_thread_time_limit pydantic-field

enable_per_process_and_thread_time_limit = None

If true then cpu_time_limit will be used as per process and thread

enable_per_process_and_thread_memory_limit pydantic-field

enable_per_process_and_thread_memory_limit = None

If true then memory_limit will be used as per process and thread

max_file_size pydantic-field

max_file_size = None

Limit file size created or modified by the program (kilobytes)

redirect_stderr_to_stdout pydantic-field

redirect_stderr_to_stdout = None

If true standard error will be redirected to standard output

enable_network pydantic-field

enable_network = None

If true program will have network access

number_of_runs pydantic-field

number_of_runs = None

Run each program number_of_runs times and take average of time and memory

callback_url pydantic-field

callback_url = None

URL on which Judge0 will issue PUT request with the submission in a request body after submission has been done

SingleFileSubmission pydantic-model

Bases: BaseSubmission, BaseModel

Request model for creating a single-file submission in Judge0.

Fields:

Source code in src/judge0_client/models/single_file_submission.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class SingleFileSubmission(BaseSubmission, BaseModel):
    """Request model for creating a single-file submission in Judge0."""

    source_code: str = Field(description="Program’s source code")
    language_id: int = Field(description="Programming language ID")
    additional_files: Mapping[str, str | bytes] | None = Field(
        default=None,
        description="Additional files that should be available alongside the source code (encoded zip)"
    )

    def to_body(self) -> dict[str, Any]:
        data = self.model_dump(exclude_none=True)
        fields_to_encode = ["source_code", "stdin", "expected_output"]
        for f in fields_to_encode:
            if f in data and data[f] is not None:
                data[f] = base64_encode(data[f])
        if "additional_files" in data:
            data["additional_files"] = create_encoded_zip(data["additional_files"])
        return data

compiler_options pydantic-field

compiler_options = None

Options for the compiler (i.e. compiler flags)

command_line_arguments pydantic-field

command_line_arguments = None

Command line arguments for the program

stdin pydantic-field

stdin = None

Input for program

expected_output pydantic-field

expected_output = None

Expected output of program. Used when you want to compare with stdout

cpu_time_limit pydantic-field

cpu_time_limit = None

Default runtime limit for every program (seconds)

cpu_extra_time pydantic-field

cpu_extra_time = None

When a time limit is exceeded, wait for extra time, before killing the program (seconds)

wall_time_limit pydantic-field

wall_time_limit = None

Limit wall-clock time in seconds (seconds)

memory_limit pydantic-field

memory_limit = None

Limit address space of the program (kilobytes)

stack_limit pydantic-field

stack_limit = None

Limit process stack (kilobytes)

max_processes_and_or_threads pydantic-field

max_processes_and_or_threads = None

Maximum number of processes and/or threads program can create

enable_per_process_and_thread_time_limit pydantic-field

enable_per_process_and_thread_time_limit = None

If true then cpu_time_limit will be used as per process and thread

enable_per_process_and_thread_memory_limit pydantic-field

enable_per_process_and_thread_memory_limit = None

If true then memory_limit will be used as per process and thread

max_file_size pydantic-field

max_file_size = None

Limit file size created or modified by the program (kilobytes)

redirect_stderr_to_stdout pydantic-field

redirect_stderr_to_stdout = None

If true standard error will be redirected to standard output

enable_network pydantic-field

enable_network = None

If true program will have network access

number_of_runs pydantic-field

number_of_runs = None

Run each program number_of_runs times and take average of time and memory

callback_url pydantic-field

callback_url = None

URL on which Judge0 will issue PUT request with the submission in a request body after submission has been done

source_code pydantic-field

source_code

Program’s source code

language_id pydantic-field

language_id

Programming language ID

additional_files pydantic-field

additional_files = None

Additional files that should be available alongside the source code (encoded zip)

MultiFileSubmission pydantic-model

Bases: BaseSubmission, BaseModel

Request model for creating a multi-file submission in Judge0.

Fields:

Source code in src/judge0_client/models/multi_file_submission.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
class MultiFileSubmission(BaseSubmission, BaseModel):
    """Request model for creating a multi-file submission in Judge0."""

    language_id: Literal[89] = Field(default=89, description="Programming language ID")
    additional_files: Mapping[str, str | bytes] = Field(
        description="Scripts to run and compile and additional files"
    )

    def to_body(self) -> dict[str, Any]:
        data = self.model_dump(exclude_none=True)
        fields_to_encode = ["stdin", "expected_output"]
        for f in fields_to_encode:
            if f in data and data[f] is not None:
                data[f] = base64_encode(data[f])
        if "additional_files" in data:
            data["additional_files"] = create_encoded_zip(data["additional_files"])
        return data

compiler_options pydantic-field

compiler_options = None

Options for the compiler (i.e. compiler flags)

command_line_arguments pydantic-field

command_line_arguments = None

Command line arguments for the program

stdin pydantic-field

stdin = None

Input for program

expected_output pydantic-field

expected_output = None

Expected output of program. Used when you want to compare with stdout

cpu_time_limit pydantic-field

cpu_time_limit = None

Default runtime limit for every program (seconds)

cpu_extra_time pydantic-field

cpu_extra_time = None

When a time limit is exceeded, wait for extra time, before killing the program (seconds)

wall_time_limit pydantic-field

wall_time_limit = None

Limit wall-clock time in seconds (seconds)

memory_limit pydantic-field

memory_limit = None

Limit address space of the program (kilobytes)

stack_limit pydantic-field

stack_limit = None

Limit process stack (kilobytes)

max_processes_and_or_threads pydantic-field

max_processes_and_or_threads = None

Maximum number of processes and/or threads program can create

enable_per_process_and_thread_time_limit pydantic-field

enable_per_process_and_thread_time_limit = None

If true then cpu_time_limit will be used as per process and thread

enable_per_process_and_thread_memory_limit pydantic-field

enable_per_process_and_thread_memory_limit = None

If true then memory_limit will be used as per process and thread

max_file_size pydantic-field

max_file_size = None

Limit file size created or modified by the program (kilobytes)

redirect_stderr_to_stdout pydantic-field

redirect_stderr_to_stdout = None

If true standard error will be redirected to standard output

enable_network pydantic-field

enable_network = None

If true program will have network access

number_of_runs pydantic-field

number_of_runs = None

Run each program number_of_runs times and take average of time and memory

callback_url pydantic-field

callback_url = None

URL on which Judge0 will issue PUT request with the submission in a request body after submission has been done

language_id pydantic-field

language_id = 89

Programming language ID

additional_files pydantic-field

additional_files

Scripts to run and compile and additional files

SubmissionResponse pydantic-model

Bases: BaseResponseModel

Response for non-waiting submission — contains only a token.

Fields:

  • token (str)
Source code in src/judge0_client/models/submission_response.py
4
5
6
7
class SubmissionResponse(BaseResponseModel):
    """Response for non-waiting submission — contains only a token."""

    token: str

SubmissionDetail pydantic-model

Bases: BaseResponseModel

Detailed information about submission execution.

Fields:

  • token (str)
  • status (SubmissionStatus)
  • stdout (str | None)
  • stderr (str | None)
  • compile_output (str | None)
  • message (str | None)
  • time (float | None)
  • memory (int | None)
  • exit_code (int | None)
  • language_id (int | None)
Source code in src/judge0_client/models/submission_detail.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
class SubmissionDetail(BaseResponseModel):
    """Detailed information about submission execution."""

    token: str
    status: SubmissionStatus
    stdout: str | None = None
    stderr: str | None = None
    compile_output: str | None = None
    message: str | None = None
    time: float | None = None
    memory: int | None = None
    exit_code: int | None = None
    language_id: int | None = None

    def decode_base64(self) -> Self:
        return self.model_copy(update={
            "stdout": base64_decode(self.stdout) if self.stdout else self.stdout,
            "stderr": base64_decode(self.stderr) if self.stderr else self.stderr,
            "compile_output": base64_decode(self.compile_output) if self.compile_output else self.compile_output,
            "message": base64_decode(self.message) if self.message else self.message,
        })

WorkersResponse pydantic-model

Bases: BaseResponseModel

Fields:

Source code in src/judge0_client/models/workers_response.py
 5
 6
 7
 8
 9
10
11
12
class WorkersResponse(BaseResponseModel):
    queue: str = Field(description="Queue name")
    size: int = Field(description="Queue size, number of submissions that are currently waiting to be processed")
    available: int = Field(description="Available number of workers")
    idle: int = Field(description="How many workers are idle")
    working: int = Field(description="How many workers are currently working")
    paused: int = Field(description="How many workers are paused")
    failed: int = Field(description="How many jobs failed")

queue pydantic-field

queue

Queue name

size pydantic-field

size

Queue size, number of submissions that are currently waiting to be processed

available pydantic-field

available

Available number of workers

idle pydantic-field

idle

How many workers are idle

working pydantic-field

working

How many workers are currently working

paused pydantic-field

paused

How many workers are paused

failed pydantic-field

failed

How many jobs failed