Skip to content

Feature: add httpx2 support with httpx fallback - #328

Open
CoderJoshDK wants to merge 4 commits into
yanyongyu:masterfrom
CoderJoshDK:httpx2
Open

CoderJoshDK wants to merge 4 commits into
yanyongyu:masterfrom
CoderJoshDK:httpx2

Conversation

@CoderJoshDK

Copy link
Copy Markdown

Deprecate the use of httpx in favor of httpx2 when supplied.

Closes #321
Replaces #324

If the environment of the caller has httpx2 installed, we use that. Otherwise, we give them a deprecation warning.

In the future, httpx should be dropped and a hard cut to the httpx2 namespace should be used. This is to help avoid client mismatch.

@yanyongyu yanyongyu added the enhancement New feature or request label Oct 1, 2026
Comment thread tests/test_httpx.py Outdated

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Aware that this file is a bit funky. Honestly, this test can be removed IMO. But up to you.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think this test could be removed. Instead, running all other tests without httpx2 in the env (using httpx) seems more meaningful.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Do you want to test like pydantic is done? I ended up having it only test 1 time in the matrix because it seems excessive to me to run it for everything. But that can be done too.

Comment thread pyproject.toml
"anyio >=3.6.1, <5.0.0",
"httpx >=0.23.0, <1.0.0",
"hishel[async,httpx] >=1.3.0, <=2.0.0",
"hishel[async,httpx] >=1.4.0, <=2.0.0",

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Bump here because this is the first version that supports httpx2. I want to avoid a really strange case where you somehow have httpx2 but not the version of hishel that supports it and you get a super strange import error / explosion. This also makes the _httpx.py file a bit more reliable in its try-except.

Comment thread githubkit/_httpx.py
Comment thread pyproject.toml
@CoderJoshDK

Copy link
Copy Markdown
Author

I am working on some important $DAYJOB things today. But after work, I will do the pyproject change you wanted and look into the failing CI. Please give me any other changes you want me to tackle (if you have any) and I will do them tonight!

Have a test run with httpx instead of httpx2
Comment on lines +51 to +54
- name: Use httpx without httpx2
if: matrix.http-client == 'httpx'
run: uv pip uninstall httpx2

@yanyongyu yanyongyu Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I think this can be achieved by adding an environment variable within githubkit to force the use of httpx. FYI, like this.

Comment on lines +5 to +7
GitHubKit installs HTTPX by default to preserve compatibility with existing transports. It prefers [HTTPX2](https://pydantic.dev/docs/httpx2/) when you install it separately. The default HTTPX path remains supported, but emits a `DeprecationWarning`. To opt in, run `pip install httpx2`, then use `import httpx2` and `httpx2.*` as in the examples below. If you remain on HTTPX, use `import httpx` and `httpx.*` instead.

Custom timeouts, URLs, proxies, transports, and responses must come from the selected package: HTTPX2 when installed, or HTTPX on the deprecated fallback path. Objects from the two packages are not interchangeable. HTTPX2 uses the operating system's trust store by default instead of HTTPX's bundled CA certificates; its logger names are `httpx2` and `httpcore2.*`.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This section can be explained to the user by adding admonition block below the original paragraph.

@CoderJoshDK

Copy link
Copy Markdown
Author

I am going to be away till next week. Next week, I will come back to this. Feel free to make any commits to my PR as you see fit or wait for me to get back.

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

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support httpx2

2 participants