Skip to content

Commit c562d00

Browse files
committed
Merge branch 'master' of github.com:judge0/judge0-py into setup-logging
2 parents 679c69b + fe58ee4 commit c562d00

File tree

6 files changed

+47
-20
lines changed

6 files changed

+47
-20
lines changed

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"special-members": False,
9898
"inherited-members": False,
9999
}
100-
autodoc_mock_imports = ["requests", "pydantic"]
100+
autodoc_mock_imports = ["httpx", "pydantic"]
101101

102102
napoleon_google_docstring = False
103103

docs/source/in_depth/client_resolution.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ If a custom client is not configured, the SDK will try to find API keys for one
2424

2525
* **Judge0 Cloud**:
2626
* ``JUDGE0_CLOUD_CE_AUTH_HEADERS`` for ``Judge0CloudCE``
27-
* ``JUDGE0_CLOUD_EXTRA_CE_AUTH_HEADERS` for ``Judge0CloudExtraCE``
27+
* ``JUDGE0_CLOUD_EXTRA_CE_AUTH_HEADERS`` for ``Judge0CloudExtraCE``
2828

2929
* **RapidAPI**:
3030
* ``JUDGE0_RAPID_API_KEY`` for both ``RapidJudge0CE`` and ``RapidJudge0ExtraCE``

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ classifiers = [
2424
"Topic :: Software Development :: Libraries :: Python Modules",
2525
"Typing :: Typed",
2626
]
27-
dependencies = ["requests>=2.28.0,<3.0.0", "pydantic>=2.0.0,<3.0.0"]
27+
dependencies = ["httpx>=0.28.1,<1.0.0", "pydantic>=2.0.0,<3.0.0"]
2828

2929
[build-system]
3030
requires = ["setuptools>=70.0"]

src/judge0/clients.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import ClassVar, Optional, Union
22

3-
import requests
3+
import httpx
44

55
from .base_types import Config, Iterable, Language, LanguageAlias
66
from .data import LANGUAGE_TO_LANGUAGE_ID
@@ -40,7 +40,7 @@ def __init__(
4040
self.endpoint = endpoint
4141
self.auth_headers = auth_headers
4242
self.retry_strategy = retry_strategy
43-
self.session = requests.Session()
43+
self.client = httpx.Client()
4444

4545
try:
4646
self.languages = self.get_languages()
@@ -53,7 +53,7 @@ def __init__(
5353
) from e
5454

5555
def __del__(self):
56-
self.session.close()
56+
self.client.close()
5757

5858
@handle_too_many_requests_error_for_preview_client
5959
def get_about(self) -> dict:
@@ -64,7 +64,7 @@ def get_about(self) -> dict:
6464
dict
6565
General information about judge0.
6666
"""
67-
response = self.session.get(
67+
response = self.client.get(
6868
f"{self.endpoint}/about",
6969
headers=self.auth_headers,
7070
)
@@ -80,7 +80,7 @@ def get_config_info(self) -> Config:
8080
Config
8181
Client's configuration.
8282
"""
83-
response = self.session.get(
83+
response = self.client.get(
8484
f"{self.endpoint}/config_info",
8585
headers=self.auth_headers,
8686
)
@@ -102,7 +102,7 @@ def get_language(self, language_id: int) -> Language:
102102
Language corresponding to the passed id.
103103
"""
104104
request_url = f"{self.endpoint}/languages/{language_id}"
105-
response = self.session.get(request_url, headers=self.auth_headers)
105+
response = self.client.get(request_url, headers=self.auth_headers)
106106
response.raise_for_status()
107107
return Language(**response.json())
108108

@@ -116,7 +116,7 @@ def get_languages(self) -> list[Language]:
116116
A list of supported languages.
117117
"""
118118
request_url = f"{self.endpoint}/languages"
119-
response = self.session.get(request_url, headers=self.auth_headers)
119+
response = self.client.get(request_url, headers=self.auth_headers)
120120
response.raise_for_status()
121121
return [Language(**lang_dict) for lang_dict in response.json()]
122122

@@ -129,7 +129,7 @@ def get_statuses(self) -> list[dict]:
129129
list of dict
130130
A list of possible submission statues.
131131
"""
132-
response = self.session.get(
132+
response = self.client.get(
133133
f"{self.endpoint}/statuses",
134134
headers=self.auth_headers,
135135
)
@@ -208,7 +208,7 @@ def create_submission(self, submission: Submission) -> Submission:
208208

209209
body = submission.as_body(self)
210210

211-
response = self.session.post(
211+
response = self.client.post(
212212
f"{self.endpoint}/submissions",
213213
json=body,
214214
params=params,
@@ -254,7 +254,7 @@ def get_submission(
254254
else:
255255
params["fields"] = "*"
256256

257-
response = self.session.get(
257+
response = self.client.get(
258258
f"{self.endpoint}/submissions/{submission.token}",
259259
params=params,
260260
headers=self.auth_headers,
@@ -291,7 +291,7 @@ def create_submissions(self, submissions: Submissions) -> Submissions:
291291

292292
submissions_body = [submission.as_body(self) for submission in submissions]
293293

294-
response = self.session.post(
294+
response = self.client.post(
295295
f"{self.endpoint}/submissions/batch",
296296
headers=self.auth_headers,
297297
params={"base64_encoded": "true"},
@@ -342,7 +342,7 @@ def get_submissions(
342342
tokens = ",".join([submission.token for submission in submissions])
343343
params["tokens"] = tokens
344344

345-
response = self.session.get(
345+
response = self.client.get(
346346
f"{self.endpoint}/submissions/batch",
347347
params=params,
348348
headers=self.auth_headers,

src/judge0/utils.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
from functools import wraps
44
from http import HTTPStatus
55

6-
from requests import HTTPError
6+
from httpx import HTTPError, HTTPStatusError
77

88
from .errors import PreviewClientLimitError
99

1010

1111
def is_http_too_many_requests_error(exception: Exception) -> bool:
1212
return (
13-
isinstance(exception, HTTPError)
14-
and exception.response is not None
13+
isinstance(exception, HTTPStatusError)
1514
and exception.response.status_code == HTTPStatus.TOO_MANY_REQUESTS
1615
)
1716

uv.lock

Lines changed: 30 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)