Skip to content

Commit 3c94acf

Browse files
mishushakovclaude
andcommitted
refactor(python-sdk): own the ProxyTypes alias
`ProxyTypes` — the public type of the `proxy` option — came from httpx's private `_types` module, imported at runtime in eleven modules. It is defined there as `Union["URL", str, "Proxy"]`, exactly the three forms the SDK's two narrowers accept, so spell it out once in `e2b.connection_config` and import it from there instead. Same public name, same type to a type checker, no private-module dependency, and a place for a pyqwest proxy type to land as the transports move off httpx. `e2b.envd.client_shared.proxy_to_url` took a bare `object` while `e2b.api.proxy_to_config` took `Optional[ProxyTypes]`; both now say the same thing. Keeping `isinstance` narrowing rather than duck-typing `.url`/`.auth` is deliberate: httpx is a required dependency here (the generated REST client is an httpx client and envd file transfers use httpx directly), so probing attributes would trade a clear `InvalidArgumentException` on a mistyped argument for no dependency savings. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent f8020ea commit 3c94acf

12 files changed

Lines changed: 27 additions & 19 deletions

File tree

packages/python-sdk/e2b/api/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88

99
import httpx
1010
from httpx import AsyncBaseTransport, BaseTransport, Limits, Timeout
11-
from httpx._types import ProxyTypes
1211
from pyqwest import Proxy
1312

1413
from e2b.api.client.client import AuthenticatedClient
1514
from e2b.api.client.types import Response
1615
from e2b.api.metadata import default_headers
17-
from e2b.connection_config import ConnectionConfig
16+
from e2b.connection_config import ConnectionConfig, ProxyTypes
1817
from e2b.exceptions import (
1918
AuthenticationException,
2019
InvalidArgumentException,

packages/python-sdk/e2b/api/client_async/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import httpx
77

8-
from httpx._types import ProxyTypes
98
from pyqwest import HTTPTransport, Request, Response
109
from pyqwest.httpx import AsyncPyqwestTransport
1110
from pyqwest.middleware.retry import RetryTransport
@@ -19,7 +18,7 @@
1918
pool_max_idle_per_host,
2019
proxy_to_config,
2120
)
22-
from e2b.connection_config import ConnectionConfig
21+
from e2b.connection_config import ConnectionConfig, ProxyTypes
2322

2423
TransportKey = Tuple[bool, Optional[ProxyTypes]]
2524

packages/python-sdk/e2b/api/client_sync/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import httpx
44
import threading
55

6-
from httpx._types import ProxyTypes
76
from pyqwest import SyncHTTPTransport, SyncRequest, SyncResponse
87
from pyqwest.httpx import PyqwestTransport
98
from pyqwest.middleware.retry import SyncRetryTransport
@@ -17,7 +16,7 @@
1716
pool_max_idle_per_host,
1817
proxy_to_config,
1918
)
20-
from e2b.connection_config import ConnectionConfig
19+
from e2b.connection_config import ConnectionConfig, ProxyTypes
2120

2221
TransportKey = Tuple[bool, Optional[ProxyTypes]]
2322

packages/python-sdk/e2b/connection_config.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
import logging
22
import os
33

4-
from typing import cast, Optional, Dict, TypedDict
4+
from typing import cast, Optional, Dict, TypedDict, Union
55

6-
from httpx._types import ProxyTypes
6+
import httpx
77
from typing_extensions import Unpack
88

99
from e2b.api.metadata import package_version
1010
from e2b.sandbox_domains import is_supported_sandbox_domain
1111

12+
ProxyTypes = Union[str, httpx.URL, httpx.Proxy]
13+
"""The forms the ``proxy`` option accepts: a URL string, an ``httpx.URL``, or
14+
an ``httpx.Proxy``.
15+
16+
Identical to ``httpx._types.ProxyTypes``, spelled out here so the SDK doesn't
17+
import httpx's private module at runtime — and so the union can grow a pyqwest
18+
proxy type as the transports move off httpx. The functions that narrow it are
19+
:func:`e2b.api.proxy_to_config` and :func:`e2b.envd.client_shared.proxy_to_url`.
20+
"""
21+
1222
REQUEST_TIMEOUT: float = 60.0 # 60 seconds
1323

1424
KEEPALIVE_PING_INTERVAL_SEC = 50 # 50 seconds

packages/python-sdk/e2b/envd/client_shared.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from connectrpc.errors import ConnectError
2424
from protobuf import Message
2525

26+
from e2b.connection_config import ProxyTypes
2627
from e2b.exceptions import InvalidArgumentException
2728

2829
# Mirror the httpx pool tuning in `e2b.api.limits` with pyqwest's equivalents.
@@ -170,7 +171,7 @@ class _RPCCompression(TypedDict):
170171
}
171172

172173

173-
def proxy_to_url(proxy: object) -> Optional[str]:
174+
def proxy_to_url(proxy: Optional[ProxyTypes]) -> Optional[str]:
174175
"""Narrow the ``proxy`` connection option to the proxy URL string pyqwest
175176
transports take (scheme http, https, socks5, or socks5h, credentials in
176177
the URL userinfo). ``httpx.URL`` and ``httpx.Proxy`` — which the REST

packages/python-sdk/e2b/volume/client_async/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
import httpx
77
from httpx import Limits
8-
from httpx._types import ProxyTypes
98

109
from e2b.api import connection_retries, make_async_logging_event_hooks
1110
from e2b.api.metadata import default_headers
11+
from e2b.connection_config import ProxyTypes
1212
from e2b.exceptions import AuthenticationException
1313
from e2b.volume.client.client import AuthenticatedClient as AsyncVolumeApiClient
1414
from e2b.volume.connection_config import VolumeConnectionConfig

packages/python-sdk/e2b/volume/client_sync/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
import httpx
66
from httpx import Limits
7-
from httpx._types import ProxyTypes
87

98
from e2b.api import connection_retries, make_logging_event_hooks
109
from e2b.api.metadata import default_headers
10+
from e2b.connection_config import ProxyTypes
1111
from e2b.exceptions import AuthenticationException
1212
from e2b.volume.client.client import AuthenticatedClient as VolumeApiClient
1313
from e2b.volume.connection_config import VolumeConnectionConfig

packages/python-sdk/e2b/volume/connection_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
from typing import Dict, Optional, TypedDict
55

6-
from httpx._types import ProxyTypes
76
from typing_extensions import Unpack
87

98
from e2b.api.metadata import package_version
9+
from e2b.connection_config import ProxyTypes
1010

1111
REQUEST_TIMEOUT: float = 60.0 # 60 seconds
1212

packages/python-sdk/e2b/volume/volume_async.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import httpx
55

6-
from httpx._types import ProxyTypes
76
from typing_extensions import Unpack
87

98
from e2b.api import handle_api_exception
@@ -19,7 +18,7 @@
1918
)
2019
from e2b.api.client.types import Response
2120
from e2b.api.client_async import get_api_client as get_core_api_client
22-
from e2b.connection_config import ApiParams, ConnectionConfig
21+
from e2b.connection_config import ApiParams, ConnectionConfig, ProxyTypes
2322
from e2b.exceptions import NotFoundException, VolumeException
2423
from e2b.volume.client.api.volumes import (
2524
get_volumecontent_volume_id_path as get_path,

packages/python-sdk/e2b/volume/volume_sync.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import httpx
66

7-
from httpx._types import ProxyTypes
87
from typing_extensions import Unpack
98

109
from e2b.api import handle_api_exception
@@ -20,7 +19,7 @@
2019
)
2120
from e2b.api.client.types import Response
2221
from e2b.api.client_sync import get_api_client as get_core_api_client
23-
from e2b.connection_config import ApiParams, ConnectionConfig
22+
from e2b.connection_config import ApiParams, ConnectionConfig, ProxyTypes
2423
from e2b.exceptions import NotFoundException, VolumeException
2524
from e2b.volume.client.api.volumes import (
2625
get_volumecontent_volume_id_path as get_path,

0 commit comments

Comments
 (0)