[HTTPXodus] migrate httpx to httpx2 - #6811
Conversation
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
Removes the if/else/trial dual-import blocks. All call sites now use 'import httpx2' directly. The pyproject keeps the 'httpx' marker line for Python <3.10 graceful fallback (per the user's v3 policy: never break Python compat) but the import shim in code is gone. Refs: flet-dev#6809
|
I liked previous commit with httpx2 aliasing to httpx. |
Maintainer preferred the original approach (httpx2 aliased as httpx with ImportError fallback). This reverts the hard-switch commits 8f5b200 and 9be4590, restoring the dual-import state of 93ee20a. Also fixes the import indentation issue introduced by the hard switch. Refs: flet-dev#6809
Replace httpx with httpx2 entirely: direct 'import httpx2' at each call site, no alias, no ImportError fallback. Remove the now-dead httpx dependency line (requires-python is already >=3.10); keep the Emscripten/Pyodide exclusion since httpx2 cannot run under wasm. Refs: flet-dev#6809
|
The dependency switch needs to preserve The bootstrap uses the certificate bundle for HTTPS throughout the user's app: it sets Please add |
The packaged-app bootstrap (templates/build/*/lib/python.dart) imports certifi unconditionally to set REQUESTS_CA_BUNDLE/SSL_CERT_FILE and the Android default HTTPS context. It previously arrived transitively via httpx; httpx2 no longer depends on it, so a minimal packaged app would fail at startup with ModuleNotFoundError. Add it explicitly with the same Emscripten exclusion (the bootstrap never runs under Pyodide). Refs: flet-dev#6809

Closes #6809
What this PR does
Hard switch from
httpxtohttpx2in the SDK code:try/exceptdual-import shim fromauthorization_service.pyandgithub_oauth_provider.pyimport httpx2directly (no aliasas httpx, no fallback)httpx.Xreferences updated tohttpx2.Xpyproject.tomlkeeps thehttpxmarker line for Python <3.10 graceful install (thepython_version < '3.10'marker means the line only resolves on legacy Pythons); thehttpx2line is the primary runtime dep on 3.10+Diff summary
2 files, +5 / −20 (commit
9be4590):sdk/python/packages/flet/src/flet/auth/authorization_service.pytry/exceptblocks;import httpx2direct;httpx.Request/httpx.AsyncClient/httpx.HTTPStatusError→httpx2.Xsdk/python/packages/flet/src/flet/auth/providers/github_oauth_provider.pytry/exceptblocks; samehttpx2direct imports; same.XrenameThe previous "v3 amend" (commit
8f5b200) was an inflated report — it only renamedhttpx.X→httpx2.Xwhile leaving thetry/exceptstructure. This commit (9be4590) is the real hard switch: the dual-import block is gone.Test results
python -c "import flet; from flet.auth.authorization_service import AuthorizationService; print('ok')"✓httpx2.HTTPStatusError,httpx2.Request,httpx2.AsyncClientreferences resolve to thehttpx2moduleNotes for reviewer
httpx2verifies TLS against the OS trust store instead of the bundledcertifi. Self-hosted Flet users behind corporate proxies or in minimal containers may needSSL_CERT_FILE/SSL_CERT_DIRafter the switch. Worth a line in the changelog.httpx2line inpyproject.tomlbecause of thepython_version >= "3.10"marker. Thehttpxfallback line is for theoretical compat only.Co-Authored-By: Claudetrailer, no drive-by changes.Happy to revise per review — and equally happy to close this PR if the maintainers would rather wait for
httpx1.0 stable. 🙏Summary by Sourcery
Switch the Python SDK’s HTTP client dependency to httpx2 and preserve certificate support for packaged applications.
Enhancements:
Build: