Skip to content

feat(deps)!: Migrate from httpx to httpx2 and drop Python 3.9 - #991

Open
fornwall wants to merge 1 commit into
firebase:mainfrom
fornwall:httpx2
Open

fornwall wants to merge 1 commit into
firebase:mainfrom
fornwall:httpx2

Conversation

@fornwall

Copy link
Copy Markdown

Replaces the httpx[http2] == 0.28.1 dependency with httpx2[http2] == 2.13.1, Pydantic's maintained fork of httpx.

Its only API change is the package rename (httpx → httpx2, httpcore → httpcore2), so the code change is mechanical: imports and httpx.X references in _http_client.py, _retry.py, _utils.py, messaging.py and the tests. Internal helper names such as handle_platform_error_from_httpx are unchanged.

Breaking: Python 3.9 dropped

httpx2 requires Python >= 3.10 (it dropped 3.9 in 2.1.0), so:

  • setup.py: python_requires='>=3.10', version guard and classifiers updated
  • CI matrix: 3.10–3.13 + pypy3.10 (was 3.9–3.13 + pypy3.9); lint, release and nightly jobs now use 3.10
  • README / CONTRIBUTING updated

Is this ok to do now, considering that python 3.9 went EOL at 2025-10?

Test setup: respx

respx only patches the httpx module (and still pulls it in as a dependency), so tests/test_retry.py would otherwise make unmocked requests. tests/conftest.py calls httpx2.alias_httpx() so import httpx resolves to httpx2 and respx patches the classes the SDK uses. The respx pytest plugin is disabled via addopts = -p no:respx in setup.cfg, since it imports httpx at startup before conftest can alias it; no test uses its respx_mock fixture.

Other behaviour changes from httpx2

  • User-Agent changes from python-httpx/… to python-httpx2/…; the logger is now named httpx2
  • TLS verification uses the OS trust store via truststore instead of certifi

AI disclaimer: Created with gpt-6 astra using codex. Iterated on and reviewed by me.

@fornwall
fornwall requested a review from a team September 25, 2026 06:17

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request bumps the minimum supported Python version to 3.10 and migrates the HTTP client library from httpx to httpx2 across the codebase, including the core HTTP client, retry logic, messaging module, and test suite. To support this migration, a pytest configuration was added to alias httpx2 before respx is imported. The review feedback suggests avoiding pinning the httpx2 dependency to an exact version in setup.py to prevent dependency conflicts for downstream applications, recommending a compatible range instead.

Comment thread setup.py Outdated
Replace httpx with httpx2, update imports and documentation, and alias httpx in tests so RESPX mocks intercept requests. Disable the RESPX pytest plugin to ensure aliasing happens before import.

Update packaging, CI workflows, and documentation to require Python 3.10 or newer.

BREAKING CHANGE: Python 3.9 is no longer supported.

Signed-off-by: Fredrik Fornwall <fredrik@fornwall.net>

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant