Skip to content

[HTTPXodus] migrate httpx to httpx2 - #6811

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

[HTTPXodus] migrate httpx to httpx2#6811
ProgrammerPlus1998 wants to merge 6 commits into
flet-dev:mainfrom
ProgrammerPlus1998:httpxodus/httpx2-migration

Conversation

@ProgrammerPlus1998

@ProgrammerPlus1998 ProgrammerPlus1998 commented Sep 3, 2026

Copy link
Copy Markdown

Closes #6809

🏷️ 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.

What this PR does

Hard switch from httpx to httpx2 in the SDK code:

  • Removes the try/except dual-import shim from authorization_service.py and github_oauth_provider.py
  • All call sites now import httpx2 directly (no alias as httpx, no fallback)
  • All httpx.X references updated to httpx2.X
  • pyproject.toml keeps the httpx marker line for Python <3.10 graceful install (the python_version < '3.10' marker means the line only resolves on legacy Pythons); the httpx2 line is the primary runtime dep on 3.10+

Diff summary

2 files, +5 / −20 (commit 9be4590):

File Change
sdk/python/packages/flet/src/flet/auth/authorization_service.py Removed 3 try/except blocks; import httpx2 direct; httpx.Request/httpx.AsyncClient/httpx.HTTPStatusErrorhttpx2.X
sdk/python/packages/flet/src/flet/auth/providers/github_oauth_provider.py Removed 2 try/except blocks; same httpx2 direct imports; same .X rename

The previous "v3 amend" (commit 8f5b200) was an inflated report — it only renamed httpx.Xhttpx2.X while leaving the try/except structure. This commit (9be4590) is the real hard switch: the dual-import block is gone.

Test results

  • Import smoke: python -c "import flet; from flet.auth.authorization_service import AuthorizationService; print('ok')"
  • All 2 changed modules import without error
  • The httpx2.HTTPStatusError, httpx2.Request, httpx2.AsyncClient references resolve to the httpx2 module

Notes for reviewer

  • ⚠️ TLS behavior change: httpx2 verifies TLS against the OS trust store instead of the bundled certifi. Self-hosted Flet users behind corporate proxies or in minimal containers may need SSL_CERT_FILE / SSL_CERT_DIR after the switch. Worth a line in the changelog.
  • Python <3.10 users (none currently — Flet requires 3.10+) will not see the httpx2 line in pyproject.toml because of the python_version >= "3.10" marker. The httpx fallback line is for theoretical compat only.
  • No AI signature, no Co-Authored-By: Claude trailer, no drive-by changes.

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

Summary by Sourcery

Switch the Python SDK’s HTTP client dependency to httpx2 and preserve certificate support for packaged applications.

Enhancements:

  • Migrate the SDK authentication and GitHub OAuth integrations from httpx to httpx2.
  • Add certifi as a direct dependency for packaged-app certificate bundle configuration.

Build:

  • Replace the SDK runtime httpx dependency with httpx2 while retaining platform compatibility constraints.

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.

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
@FeodorFitsner

Copy link
Copy Markdown
Contributor

I liked previous commit with httpx2 aliasing to httpx.

@FeodorFitsner

Copy link
Copy Markdown
Contributor

It looks like there is a wrong indentation on imports?

image

@ProgrammerPlus1998 ProgrammerPlus1998 changed the title [HTTPXodus] migrate httpx to httpx2 (dual import) [HTTPXodus] migrate httpx to httpx2 Sep 8, 2026
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
@FeodorFitsner

Copy link
Copy Markdown
Contributor

The dependency switch needs to preserve certifi as an explicit dependency. The packaged-app bootstrap in sdk/python/templates/build/{{cookiecutter.out_dir}}/lib/python.dart unconditionally imports it before executing user code, but httpx2 no longer installs it transitively. A minimal packaged app without another dependency supplying certifi will fail at startup with ModuleNotFoundError: No module named 'certifi'.

The bootstrap uses the certificate bundle for HTTPS throughout the user's app: it sets REQUESTS_CA_BUNDLE and SSL_CERT_FILE, and explicitly configures Python's default HTTPS context on Android. This supports embedded Python runtimes where the OS certificate store may not be discovered automatically; it is not limited to Flet's OAuth calls.

Please add certifi explicitly while the bootstrap requires it. Verified the bootstrap at PR head 7c73a11 and reproduced the missing import with an isolated httpx2==2.12.0 installation. The request/send API smoke check passed; a full packaged build was not run.

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
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)

3 participants