Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dark-adults-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@e2b/python-sdk': minor
---

http2 support for python sdk
19 changes: 11 additions & 8 deletions packages/python-sdk/e2b/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,19 @@ def __init__(
kwargs.pop("auth_header_name", None)
kwargs.pop("prefix", None)

httpx_args = {
"event_hooks": {
"request": [self._log_request],
"response": [self._log_response],
},
"transport": transport,
}
if transport is None:
httpx_args["proxy"] = config.proxy

super().__init__(
base_url=config.api_url,
httpx_args={
"event_hooks": {
"request": [self._log_request],
"response": [self._log_response],
},
"proxy": config.proxy,
"transport": transport,
},
httpx_args=httpx_args,
headers=headers,
token=token or "",
auth_header_name=auth_header_name,
Expand Down
1 change: 1 addition & 0 deletions packages/python-sdk/e2b/api/client_async/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def get_transport(config: ConnectionConfig) -> AsyncTransportWithLogger:
transport = AsyncTransportWithLogger(
limits=limits,
proxy=config.proxy,
http2=True,
)
AsyncTransportWithLogger._instances[loop_id] = transport
return transport
1 change: 1 addition & 0 deletions packages/python-sdk/e2b/api/client_sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def get_transport(config: ConnectionConfig) -> TransportWithLogger:
transport = TransportWithLogger(
limits=limits,
proxy=config.proxy,
http2=True,
Comment thread
matthewlouisbrockman marked this conversation as resolved.
)
Comment thread
matthewlouisbrockman marked this conversation as resolved.
TransportWithLogger.singleton = transport
return transport
42 changes: 41 additions & 1 deletion packages/python-sdk/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/python-sdk/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ wcmatch = "^10.1"
protobuf = ">=4.21.0"
httpcore = "^1.0.5"
httpx = ">=0.27.0, <1.0.0"
h2 = ">=4,<5"
attrs = ">=23.2.0"
packaging = ">=24.1"
typing-extensions = ">=4.1.0"
Expand Down
49 changes: 49 additions & 0 deletions packages/python-sdk/tests/test_api_client_transport.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import asyncio

import pytest

from e2b.api.client_async import AsyncTransportWithLogger
from e2b.api.client_async import get_api_client as get_async_api_client
from e2b.api.client_sync import TransportWithLogger
from e2b.api.client_sync import get_api_client as get_sync_api_client
from e2b.connection_config import ConnectionConfig


def test_sync_api_client_proxy_uses_explicit_transport():
TransportWithLogger.singleton = None
config = ConnectionConfig(
api_key="test",
proxy="http://127.0.0.1:9999",
)

api_client = get_sync_api_client(config)
httpx_client = api_client.get_httpx_client()

try:
assert "proxy" not in api_client._httpx_args
assert httpx_client._transport is TransportWithLogger.singleton
assert httpx_client._mounts == {}
finally:
httpx_client.close()
TransportWithLogger.singleton = None


@pytest.mark.asyncio
async def test_async_api_client_proxy_uses_explicit_transport():
AsyncTransportWithLogger._instances.clear()
config = ConnectionConfig(
api_key="test",
proxy="http://127.0.0.1:9999",
)

api_client = get_async_api_client(config)
httpx_client = api_client.get_async_httpx_client()
transport = AsyncTransportWithLogger._instances[id(asyncio.get_running_loop())]

try:
assert "proxy" not in api_client._httpx_args
assert httpx_client._transport is transport
assert httpx_client._mounts == {}
finally:
await httpx_client.aclose()
AsyncTransportWithLogger._instances.clear()
Loading