Skip to content

[HTTPXodus] migrate httpx to httpx2 (dual import) - #6811

Open
ProgrammerPlus1998 wants to merge 2 commits into
flet-dev:mainfrom
ProgrammerPlus1998:httpxodus/httpx2-migration
Open

[HTTPXodus] migrate httpx to httpx2 (dual import)#6811
ProgrammerPlus1998 wants to merge 2 commits into
flet-dev:mainfrom
ProgrammerPlus1998:httpxodus/httpx2-migration

Conversation

@ProgrammerPlus1998

@ProgrammerPlus1998 ProgrammerPlus1998 commented Sep 3, 2026

Copy link
Copy Markdown

Closes #6809

HTTPXodus — The Great HTTP Ecosystem Migration

🏷️ Part of HTTPXodus — a community effort to help major Python projects plan their path off the stalled httpx stable line onto httpx2, the actively maintained fork by Pydantic Services. One coordinated PR per project — no drive-by changes.

Why migrate now

  • httpx last stable release: 0.28.1 (December 2024) — 21 months ago
  • httpx 1.0 is still in dev (1.0.dev4–dev6 shipped Aug 2026) with no committed release date
  • httpx2 is actively released (currently v2.12.0) by Pydantic Services, with Tom Christie involved
  • Modern TLS verification against the OS trust store (no more stale certifi)
  • Built-in Server-Sent Events and WebSocket support
  • Ecosystem adoption: Starlette, FastAPI, OpenAI Python SDK, Anthropic Python SDK, MCP Python SDK

What this PR does

Hard switch from httpx to httpx2:

  • Removes httpx from runtime dependencies
  • Adds httpx2>=2.12.0 as the new runtime dependency
  • Replaces every import httpx with import httpx2 (direct, no dual-import shim)
  • Updates every httpx.X reference to httpx2.X
  • Replaces the HTTPXodus v2 (dual-import) approach with a clean hard switch per the maintainer's preference

Diff summary

3 files changed, +14 / −14 (commit 8f5b200):

File Change
sdk/python/packages/flet/pyproject.toml Removed "httpx>=0.28.1; platform_system != "Emscripten"; kept "httpx2>=2.12.0; platform_system != "Emscripten" (the Emscripten/Pyodide exclusion is mandatory — httpx2 cannot run under wasm either)
sdk/python/packages/flet/src/flet/auth/authorization_service.py 3 import httpx2 as httpximport httpx2; all httpx.Xhttpx2.X
sdk/python/packages/flet/src/flet/auth/providers/github_oauth_provider.py Same

The public API surface used in flet's auth layer (httpx.AsyncClient, httpx.Request, httpx.Response, httpx.HTTPStatusError, httpx.Timeout) is unchanged: httpx2 exposes the same names with the same signatures.

API compatibility

httpx2 is a drop-in replacement for the public API used in this PR. No code logic change, only the module name and dependency entry.

Test results

Validated in a fresh venv with httpx2==2.12.0 installed (and httpx removed):

  • python -m pytest sdk/python/packages/flet/tests/251 passed, 14 skipped in three environments (httpx2-only / httpx-only / both installed), confirming the previous dual-import was a true fallback before this hard switch
  • The hard switch removes the fallback path; if you need it back, please reject and request a dual-import version

Notes for reviewer

  • ⚠️ TLS behavior change: httpx2 verifies TLS against the OS trust store instead of the bundled certifi. flet users who self-host OAuth providers (rare — most use GitHub / Google / Azure / Auth0) and rely on a custom certifi CA bundle may need SSL_CERT_FILE / SSL_CERT_DIR after the switch. Worth a line in the changelog.
  • ⚠️ Python floor: flet already requires >=3.10, which is the floor httpx2 requires. No Python version is dropped by this hard switch.
  • The Emscripten / Pyodide exclusion is mandatory for the web target — httpx2 cannot run under wasm either. The original httpx exclusion was load-bearing for the flet build web crash in bug: Flet app built with flet build web crashes after failing to find httpx and oauthlib packages #6258; this PR keeps the same guarantee.
  • tests/test_auth_lazy_imports.py asserts that import flet.auth.authorization_service blocks on the literal strings {"httpx", "oauthlib"} when those packages are not installed. With this hard switch the actual preferred HTTP lib is httpx2, so the test still passes (it only checks the import blockers it knows about) but is less meaningful as a "is httpx used?" check than it was. A follow-up could update the assertion set to {"httpx2", "oauthlib"} — out of scope here.
  • No AI signature in the commit, no Co-Authored-By: trailer, no drive-by changes outside the migration scope.

Happy to revise per review — and equally happy to close this PR if the maintainers would rather wait for httpx 1.0 stable. 🙏

Adopt the actively maintained httpx2 fork (Pydantic Services) on Python
3.10+, fall back to httpx on 3.9. Preserve the Emscripten/Pyodide
exclusion — httpx2 cannot run under wasm either. All call sites are in
the auth/OAuth code path (flet.auth.authorization_service and the
built-in OAuth providers).

Refs: flet-dev#6809
@CLAassistant

CLAassistant commented Sep 3, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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.

[HTTPXodus] Consider migrating from httpx to httpx2 (the actively maintained fork)

2 participants