Skip to content

Commit 47128fa

Browse files
Merge be50779 into 76f5eff
2 parents 76f5eff + be50779 commit 47128fa

7 files changed

Lines changed: 109 additions & 9 deletions

File tree

.changeset/dark-adults-join.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@e2b/python-sdk': minor
3+
---
4+
5+
http2 support for python sdk

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,19 @@ def __init__(
132132
kwargs.pop("auth_header_name", None)
133133
kwargs.pop("prefix", None)
134134

135+
httpx_args = {
136+
"event_hooks": {
137+
"request": [self._log_request],
138+
"response": [self._log_response],
139+
},
140+
"transport": transport,
141+
}
142+
if transport is None:
143+
httpx_args["proxy"] = config.proxy
144+
135145
super().__init__(
136146
base_url=config.api_url,
137-
httpx_args={
138-
"event_hooks": {
139-
"request": [self._log_request],
140-
"response": [self._log_response],
141-
},
142-
"proxy": config.proxy,
143-
"transport": transport,
144-
},
147+
httpx_args=httpx_args,
145148
headers=headers,
146149
token=token or "",
147150
auth_header_name=auth_header_name,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def get_transport(config: ConnectionConfig) -> AsyncTransportWithLogger:
4646
transport = AsyncTransportWithLogger(
4747
limits=limits,
4848
proxy=config.proxy,
49+
http2=True,
4950
)
5051
AsyncTransportWithLogger._instances[loop_id] = transport
5152
return transport

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def get_transport(config: ConnectionConfig) -> TransportWithLogger:
4545
transport = TransportWithLogger(
4646
limits=limits,
4747
proxy=config.proxy,
48+
http2=True,
4849
)
4950
TransportWithLogger.singleton = transport
5051
return transport

packages/python-sdk/poetry.lock

Lines changed: 41 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/python-sdk/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ wcmatch = "^10.1"
1616
protobuf = ">=4.21.0"
1717
httpcore = "^1.0.5"
1818
httpx = ">=0.27.0, <1.0.0"
19+
h2 = ">=4,<5"
1920
attrs = ">=23.2.0"
2021
packaging = ">=24.1"
2122
typing-extensions = ">=4.1.0"
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import asyncio
2+
3+
import pytest
4+
5+
from e2b.api.client_async import AsyncTransportWithLogger
6+
from e2b.api.client_async import get_api_client as get_async_api_client
7+
from e2b.api.client_sync import TransportWithLogger
8+
from e2b.api.client_sync import get_api_client as get_sync_api_client
9+
from e2b.connection_config import ConnectionConfig
10+
11+
12+
def test_sync_api_client_proxy_uses_explicit_transport():
13+
TransportWithLogger.singleton = None
14+
config = ConnectionConfig(
15+
api_key="test",
16+
proxy="http://127.0.0.1:9999",
17+
)
18+
19+
api_client = get_sync_api_client(config)
20+
httpx_client = api_client.get_httpx_client()
21+
22+
try:
23+
assert "proxy" not in api_client._httpx_args
24+
assert httpx_client._transport is TransportWithLogger.singleton
25+
assert httpx_client._mounts == {}
26+
finally:
27+
httpx_client.close()
28+
TransportWithLogger.singleton = None
29+
30+
31+
@pytest.mark.asyncio
32+
async def test_async_api_client_proxy_uses_explicit_transport():
33+
AsyncTransportWithLogger._instances.clear()
34+
config = ConnectionConfig(
35+
api_key="test",
36+
proxy="http://127.0.0.1:9999",
37+
)
38+
39+
api_client = get_async_api_client(config)
40+
httpx_client = api_client.get_async_httpx_client()
41+
transport = AsyncTransportWithLogger._instances[id(asyncio.get_running_loop())]
42+
43+
try:
44+
assert "proxy" not in api_client._httpx_args
45+
assert httpx_client._transport is transport
46+
assert httpx_client._mounts == {}
47+
finally:
48+
await httpx_client.aclose()
49+
AsyncTransportWithLogger._instances.clear()

0 commit comments

Comments
 (0)