API Module

judge0.api.async_execute(*, client=None, submissions=None, source_code=None, test_cases=None, **kwargs)

Create submission(s).

Aliases: async_run.

Parameters:
  • client (Client or Flavor, optional) – A client where submissions should be created. If None, will try to be resolved.

  • submissions (Submission or Submissions, optional) – Submission or submissions for execution.

  • source_code (str, optional) – A source code of a program.

  • test_cases (TestCaseType or TestCases, optional) – A single test or a list of test cases

Returns:

A single submission if submissions arguments is of type Submission or source_code argument is provided, and test_cases argument is of type TestCase. Otherwise returns a list of submissions.

Return type:

Submission or Submissions

Raises:
  • ClientResolutionError – If client cannot be resolved from the submissions or the flavor.

  • ValueError – If both or neither submissions and source_code arguments are provided.

judge0.api.async_run(*, client=None, submissions=None, source_code=None, test_cases=None, **kwargs)

Create submission(s).

Aliases: async_run.

Parameters:
  • client (Client or Flavor, optional) – A client where submissions should be created. If None, will try to be resolved.

  • submissions (Submission or Submissions, optional) – Submission or submissions for execution.

  • source_code (str, optional) – A source code of a program.

  • test_cases (TestCaseType or TestCases, optional) – A single test or a list of test cases

Returns:

A single submission if submissions arguments is of type Submission or source_code argument is provided, and test_cases argument is of type TestCase. Otherwise returns a list of submissions.

Return type:

Submission or Submissions

Raises:
  • ClientResolutionError – If client cannot be resolved from the submissions or the flavor.

  • ValueError – If both or neither submissions and source_code arguments are provided.

judge0.api.create_submissions(*, client=None, submissions=None)

Universal function for creating submissions to the client.

Parameters:
  • client (Client or Flavor, optional) – A client or client flavor where submissions should be created.

  • submissions (Submission or Submissions, optional) – Submission(s) to create.

Raises:

ClientResolutionError – Raised if client resolution fails.

Return type:

Union[Submission, Sequence[Submission]]

judge0.api.create_submissions_from_test_cases(submissions, test_cases=None)

Create submissions from the submission and test case pairs.

Function always returns a deep copy so make sure you are using the returned submission(s).

Parameters:
  • submissions (Submission or Submissions) – Base submission(s) that need to be expanded with test cases.

  • test_cases (TestCaseType or TestCases) – Test cases.

Returns:

A single submission if submissions arguments is of type Submission or source_code argument is provided, and test_cases argument is of type TestCase. Otherwise returns a list of submissions.

Return type:

Submissions or Submissions

judge0.api.execute(*, client=None, submissions=None, source_code=None, test_cases=None, **kwargs)

Create submission(s) and wait for their finish.

Aliases: execute, run, sync_run.

Parameters:
  • client (Client or Flavor, optional) – A client where submissions should be created. If None, will try to be resolved.

  • submissions (Submission or Submissions, optional) – Submission(s) for execution.

  • source_code (str, optional) – A source code of a program.

  • test_cases (TestCaseType or TestCases, optional) – A single test or a list of test cases

Returns:

A single submission if submissions arguments is of type Submission or source_code argument is provided, and test_cases argument is of type TestCase. Otherwise returns a list of submissions.

Return type:

Submission or Submissions

Raises:
  • ClientResolutionError – If client cannot be resolved from the submissions or the flavor.

  • ValueError – If both or neither submissions and source_code arguments are provided.

judge0.api.get_client(flavor=Flavor.CE)

Resolve client from API keys from environment or default to preview client.

Parameters:

flavor (Flavor) – Flavor of Judge0 Client.

Returns:

An object of base type Client and the specified flavor.

Return type:

Client

judge0.api.get_submissions(*, client=None, submissions=None, fields=None)

Get submission (status) from a client.

Parameters:
  • client (Client or Flavor, optional) – A client or client flavor where submissions should be checked.

  • submissions (Submission or Submissions, optional) – Submission(s) to update.

  • fields (str or sequence of str, optional) – Submission attributes that need to be updated. Defaults to all attributes.

Raises:

ClientResolutionError – Raised if client resolution fails.

Return type:

Union[Submission, Sequence[Submission]]

judge0.api.run(*, client=None, submissions=None, source_code=None, test_cases=None, **kwargs)

Create submission(s) and wait for their finish.

Aliases: execute, run, sync_run.

Parameters:
  • client (Client or Flavor, optional) – A client where submissions should be created. If None, will try to be resolved.

  • submissions (Submission or Submissions, optional) – Submission(s) for execution.

  • source_code (str, optional) – A source code of a program.

  • test_cases (TestCaseType or TestCases, optional) – A single test or a list of test cases

Returns:

A single submission if submissions arguments is of type Submission or source_code argument is provided, and test_cases argument is of type TestCase. Otherwise returns a list of submissions.

Return type:

Submission or Submissions

Raises:
  • ClientResolutionError – If client cannot be resolved from the submissions or the flavor.

  • ValueError – If both or neither submissions and source_code arguments are provided.

judge0.api.sync_execute(*, client=None, submissions=None, source_code=None, test_cases=None, **kwargs)

Create submission(s) and wait for their finish.

Aliases: execute, run, sync_run.

Parameters:
  • client (Client or Flavor, optional) – A client where submissions should be created. If None, will try to be resolved.

  • submissions (Submission or Submissions, optional) – Submission(s) for execution.

  • source_code (str, optional) – A source code of a program.

  • test_cases (TestCaseType or TestCases, optional) – A single test or a list of test cases

Returns:

A single submission if submissions arguments is of type Submission or source_code argument is provided, and test_cases argument is of type TestCase. Otherwise returns a list of submissions.

Return type:

Submission or Submissions

Raises:
  • ClientResolutionError – If client cannot be resolved from the submissions or the flavor.

  • ValueError – If both or neither submissions and source_code arguments are provided.

judge0.api.sync_run(*, client=None, submissions=None, source_code=None, test_cases=None, **kwargs)

Create submission(s) and wait for their finish.

Aliases: execute, run, sync_run.

Parameters:
  • client (Client or Flavor, optional) – A client where submissions should be created. If None, will try to be resolved.

  • submissions (Submission or Submissions, optional) – Submission(s) for execution.

  • source_code (str, optional) – A source code of a program.

  • test_cases (TestCaseType or TestCases, optional) – A single test or a list of test cases

Returns:

A single submission if submissions arguments is of type Submission or source_code argument is provided, and test_cases argument is of type TestCase. Otherwise returns a list of submissions.

Return type:

Submission or Submissions

Raises:
  • ClientResolutionError – If client cannot be resolved from the submissions or the flavor.

  • ValueError – If both or neither submissions and source_code arguments are provided.

judge0.api.wait(*, client=None, submissions=None, retry_strategy=None)

Wait for all the submissions to finish.

Parameters:
  • client (Client or Flavor, optional) – A client or client flavor where submissions should be checked.

  • submissions (Submission or Submissions) – Submission(s) to wait for.

  • retry_strategy (RetryStrategy, optional) – A retry strategy.

Raises:

ClientResolutionError – Raised if client resolution fails.

Return type:

Union[Submission, Sequence[Submission]]