Skip to content

feat(python-sdk): use pyqwest native HTTP/2 connection balancing - #1931

Draft
devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1790937617-pyqwest-native-balancing
Draft

devin-ai-integration[bot] wants to merge 2 commits into
mainfrom
devin/1790937617-pyqwest-native-balancing

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

curioswitch/pyqwest#246 adds client-side load balancing to pyqwest's pool: it spreads an origin's HTTP/2 streams over connections by free stream capacity (from the server's SETTINGS_MAX_CONCURRENT_STREAMS), dials another connection only once every existing one is full, and caps connections per resolved address via max_connections_per_address. That is what our Python-side ConnectionBalancer / BalancingTransport did by fanning out over multiple pyqwest transports, so this PR drops them and uses one native transport.

# before: ConnectionRetryTransport(BalancingTransport(ConnectionBalancer(build)))
# after
ConnectionRetryTransport(
    SyncHTTPTransport(..., max_connections_per_address=max_connections),  # HTTPTransport for async
    max_retries=connection_retries,
)
  • E2B_MAX_CONNECTIONS (default 200) now maps to max_connections_per_address. Past the cap, a request waits for a stream on an existing connection (previously: piled onto the least-loaded one, same effect).
  • E2B_STREAMS_PER_CONNECTION is removed — the per-connection limit now comes from the server (envd edge advertises 100).
  • Removed ConnectionBalancer, PooledConnection, request_origin, BalancingTransport, _TrackedContent; response-lifetime slot accounting is now handled by pyqwest holding the hyper-util connection lease in response extensions until the body completes/closes.
  • test_envd_stream_capacity.py rewritten to assert the native pool's behavior against the local HTTP/2 frame server (waves of 80 streams at a 100-stream limit → 1, 2, 3 connections, freed streams reused; at a cap of 2 connections × 10 streams the 21st request waits until a stream closes), sync and async. Balancer unit tests removed.

Unreleased pyqwest — do not release until fixed

pyqwest with #246 is not on PyPI yet, so packages/python-sdk/pyproject.toml pins it via a [tool.uv.sources] git source at the merge commit c4aae51 (version 0.11.0 there) and the floor is bumped to pyqwest>=0.11.0,<0.12. The code-interpreter-python and desktop-python lockfiles are relocked because they pull e2b from the workspace path and inherit that source. tool.uv.sources is not included in published metadata, so before merging/releasing: drop the source block, set the floor to the actual pyqwest release, and uv lock all three packages. Until then, uv sync builds pyqwest from source (needs a Rust toolchain; ~1.5 min). pyqwest#246 also builds against [patch.crates-io] forks of h2/hyper/hyper-util — worth confirming those land upstream (or that pyqwest ships wheels built from them) before relying on it.

Link to Devin session: https://app.devin.ai/sessions/81af1a093fda4f22a89e3c1e4d78047c
Open in Devin Desktop: https://app.devin.ai/desktop/session/81af1a093fda4f22a89e3c1e4d78047c?variant=devin
Requested by: @mishushakov

Co-Authored-By: mish@e2b.dev <mish@e2b.dev>
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@cla-bot cla-bot Bot added the cla-signed label Oct 2, 2026
@changeset-bot

changeset-bot Bot commented Oct 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a5c3bc1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@e2b/python-sdk Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Co-Authored-By: mish@e2b.dev <mish@e2b.dev>

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checked the changed code for parity (T-1–T-2), API shape and exports (T-3, T-54), streaming and timeouts (T-26–T-31, T-45–T-48), configuration (T-49–T-53), compatibility (T-65–T-68), and documentation (T-69–T-74): 0 TASTE violations found.

@github-actions

github-actions Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Package Artifacts

Built from 57199b9. Download artifacts from this workflow run.

JS SDK (e2b@2.52.1-devin-1790937617-pyqwest-native-balancing.0):

npm install ./e2b-2.52.1-devin-1790937617-pyqwest-native-balancing.0.tgz

CLI (@e2b/cli@2.21.1-devin-1790937617-pyqwest-native-balancing.0):

npm install ./e2b-cli-2.21.1-devin-1790937617-pyqwest-native-balancing.0.tgz

Code Interpreter JS SDK (@e2b/code-interpreter@2.8.1-devin-1790937617-pyqwest-native-balancing.0):

npm install ./e2b-code-interpreter-2.8.1-devin-1790937617-pyqwest-native-balancing.0.tgz

Desktop JS SDK (@e2b/desktop@2.4.1-devin-1790937617-pyqwest-native-balancing.0):

npm install ./e2b-desktop-2.4.1-devin-1790937617-pyqwest-native-balancing.0.tgz

Python SDK (e2b==2.52.0+devin.1790937617.pyqwest.native.balancing):

pip install ./e2b-2.52.0+devin.1790937617.pyqwest.native.balancing-py3-none-any.whl

Code Interpreter Python SDK (e2b-code-interpreter==2.10.1+devin.1790937617.pyqwest.native.balancing):

pip install ./e2b_code_interpreter-2.10.1+devin.1790937617.pyqwest.native.balancing-py3-none-any.whl

Desktop Python SDK (e2b-desktop==2.6.0+devin.1790937617.pyqwest.native.balancing):

pip install ./e2b_desktop-2.6.0+devin.1790937617.pyqwest.native.balancing-py3-none-any.whl

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant