Skip to content

Commit 48df1b9

Browse files
authored
Add docs for client resolution. (#30)
1 parent f9b2e61 commit 48df1b9

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed
Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,55 @@
11
Client Resolution
22
=================
33

4-
TODO: Describe the approach to client resolution. See `_get_implicit_client`.
4+
The Judge0 Python SDK supports two main client flavors: Community Edition (CE) and Extra Community Edition (Extra CE), which correspond to the Judge0 Cloud editions. When you use functions like ``judge0.run`` or ``judge0.execute`` without explicitly providing a client instance, the SDK automatically resolves and initializes a client for you. This process, handled by the internal ``_get_implicit_client`` function, follows a specific order of priority.
5+
6+
The SDK determines which client to use based on environment variables. Here's the resolution order:
7+
8+
1. **Custom Client (Self-Hosted)**
9+
10+
The SDK first checks for a self-hosted Judge0 instance. If you have your own deployment of Judge0, you can configure the SDK to use it by setting the following environment variables:
11+
12+
* For CE flavor:
13+
* ``JUDGE0_CE_ENDPOINT``: The URL of your self-hosted Judge0 CE instance.
14+
* ``JUDGE0_CE_AUTH_HEADERS``: A JSON string representing the authentication headers.
15+
* For Extra CE flavor:
16+
* ``JUDGE0_EXTRA_CE_ENDPOINT``: The URL of your self-hosted Judge0 Extra CE instance.
17+
* ``JUDGE0_EXTRA_CE_AUTH_HEADERS``: A JSON string representing the authentication headers.
18+
19+
If these variables are set, the SDK will initialize a ``Client`` instance with your custom endpoint and headers.
20+
21+
2. **Hub Clients**
22+
23+
If a custom client is not configured, the SDK will try to find API keys for one of the supported hub clients. The SDK checks for the following environment variables in order:
24+
25+
* **Judge0 Cloud**:
26+
* ``JUDGE0_CLOUD_CE_AUTH_HEADERS`` for ``Judge0CloudCE``
27+
* ``JUDGE0_CLOUD_EXTRA_CE_AUTH_HEADERS` for ``Judge0CloudExtraCE``
28+
29+
* **RapidAPI**:
30+
* ``JUDGE0_RAPID_API_KEY`` for both ``RapidJudge0CE`` and ``RapidJudge0ExtraCE``
31+
32+
* **AllThingsDev**:
33+
* ``JUDGE0_ATD_API_KEY`` for both ``ATDJudge0CE`` and ``ATDJudge0ExtraCE``
34+
35+
The first API key found determines the client that will be used.
36+
37+
3. **Preview Client**
38+
39+
If none of the above environment variables are set, the SDK falls back to using a **preview client**. This is an unauthenticated client that connects to the official Judge0 Cloud service. It initializes ``Judge0CloudCE()`` and ``Judge0CloudExtraCE()`` for the CE and Extra CE flavors, respectively.
40+
41+
When the preview client is used, a warning message is logged to the console, as this option is not recommended for production use. To suppress this warning, you can set the ``JUDGE0_SUPPRESS_PREVIEW_WARNING`` environment variable.
42+
43+
Example Resolution Flow
44+
-----------------------
45+
46+
When you call a function like ``judge0.run(..., flavor=judge0.CE)``, the SDK will:
47+
48+
1. Check if ``JUDGE0_IMPLICIT_CE_CLIENT`` is already initialized. If so, use it.
49+
2. Check for ``JUDGE0_CE_ENDPOINT`` and ``JUDGE0_CE_AUTH_HEADERS`` to configure a ``Client``.
50+
3. Check for ``JUDGE0_CLOUD_CE_AUTH_HEADERS`` to configure a ``Judge0CloudCE`` client.
51+
4. Check for ``JUDGE0_RAPID_API_KEY`` to configure a ``RapidJudge0CE`` client.
52+
5. Check for ``JUDGE0_ATD_API_KEY`` to configure an ``ATDJudge0CE`` client.
53+
6. If none of the above are found, initialize a preview ``Judge0CloudCE`` client and log a warning.
54+
55+
This implicit client resolution makes it easy to get started with the Judge0 Python SDK while providing the flexibility to configure it for different environments and services.

0 commit comments

Comments
 (0)