Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 4 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

httpx

Call web services from Python, sync or async.

HTTP clients and networkingPYPI

GitHubWebsite

1. License

“Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met”

Allowed in paid and closed-source apps; keep the copyright notice and license text with any copy of its code.

github.com/encode/httpx/blob/master/LICENSE.md

From the package registry and GitHub, checked daily; card checked Nov 11, 2026. Tap a verdict to see its source.How we checkedReport an error

What httpx does

HTTPX is a free Python library your app uses to talk to other web services, such as a payment provider, a weather service or an AI model. It works in plain scripts and in async web apps, and it gives up on slow servers after 5 seconds by default. It is the usual pick when code that used Requests has to run inside an async app.

What people build with it

Call an outside service safely

Your backend asks a shipping or payment service for data, waits at most 10 seconds and stops with a clear error when the answer is an error page.

Many calls at once in async apps

A FastAPI page needs prices from five places; your app asks all five at the same time instead of one after another.

Test code without real network calls

In tests, your assistant swaps the network for a fake that returns ready answers, so tests run offline and never hit a paid service.

Download big files without filling memory

Your app saves a large export or video to disk piece by piece instead of holding the whole file in memory.

Test your own FastAPI app directly

Tests call your FastAPI or other async web app straight in Python, with no server started.

Faster calls to AI model services Idea

An app that sends many requests to one AI service turns on HTTP/2, so they share one connection.

httpx popularity

78 / 100
Gid Score, #140 overall
198M
downloads a week, pypi
15.8K
GitHub stars
280
agent projects use it
httpx: downloads per weekPyPI, httpx 196,467,718
httpx: GitHub starsencode/httpx 15,844

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How httpx is used

  • httpx is a dependency in 280 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (17.3% of the 1,623 Python ones), #3 of 126 in http clients and networking.
  • Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 685; those are left out of every share on this page.
  • The most used alternative in our scan is Requests (425 projects).
  • Projects that use it most often also use Pydantic (56.8%), Uvicorn (52.5%), python-dotenv (50.4%).
  • It is more common in projects set up for OpenClaw (7.8%) than for Devin Desktop (2.2%).

By coding agent

144 projects, 4.4%
128 projects, 4.2%
85 projects, 3.5%
26 projects, 7.8%
16 projects, 3.4%
13 projects, 3.8%
11 projects, 2.3%
6 projects, 2.2%

Often used with

In 56.8% of its projects
In 52.5% of its projects
In 50.4% of its projects
In 48.6% of its projects
In 43.9% of its projects
In 32.9% of its projects
In 32.1% of its projects
In 26.1% of its projects

httpx in practice

Strengths

Close to requests, with async on the side

The site lists "a broadly requests-compatible API" among its features. Calls are synchronous by default, and async support is there "if you need it".

Calls into WSGI and ASGI apps without a socket

httpx can send requests directly to a WSGI or ASGI application rather than to a network address. The docs list this among the features.

raise_for_status() chains inline

<code>raise_for_status()</code> raises <code>HTTPStatusError</code> on non-2xx responses. On success it returns the response itself, so <code>httpx.get('...').raise_for_status().json()</code> works in one line.

Streaming without loading the whole body

<code>httpx.stream(...)</code> is used as a context manager. You iterate with <code>iter_bytes()</code>, <code>iter_text()</code> or <code>iter_lines()</code>. <code>iter_raw()</code> skips content decoding entirely.

Watch out for

Intermittent ReadError reported under heavy traffic

Miguel Mendez reports random crashes ending in <code>httpx.ReadError</code> from his async client as traffic grew. The error appeared only under heavy traffic, and not every time. He calls it a generic error that "doesn’t give much detail". He then found a GitHub issue that, in his words, "provided insight into the performance limitations of httpx when compared to aiohttp", and switched to aiohttp. He does not pin down a root cause.

HTTP/2 and SOCKS need extras

The dependency list marks HTTP/2 support (<code>h2</code>) and SOCKS proxy support (<code>socksio</code>) as optional, installed with <code>httpx[http2]</code> and <code>httpx[socks]</code>. A plain <code>pip install httpx</code> does not include them.

Python 3.9+, and two pages name different brotli packages

HTTPX requires Python 3.9+. Brotli and zstd decoding come from the <code>httpx[brotli,zstd]</code> extras. The site's dependency list names <code>brotli</code> or <code>brotlicffi</code> for brotli decoding. The quickstart page instead says "If brotlipy is installed".

A first GET request

>>> import httpx
>>> r = httpx.get('https://www.example.org/')
>>> r
<Response [200 OK]>
>>> r.status_code
200
>>> r.headers['content-type']
'text/html; charset=UTF-8'
>>> r.text
'<!doctype html>\n<html>\n<head>\n<title>Example Domain</title>...'

More about httpx

Funding
  • GitHub Sponsors: https://github.com/encode
  • 29 GitHub sponsors

See all

Head to head
Packages around it
  • pydantic: Data validation
  • uvicorn: ASGI server
  • python-dotenv: .env file loader
  • fastapi: Web API framework
  • mcp: Model Context Protocol SDK
  • pydantic-settings: Settings from env vars
More in HTTP clients and networking

Alternatives

httpx This page

BSDGid 78198M/wk

Requests

Pick Requests for plain sync scripts where async is never needed; it follows redirects by default and has no default timeout.

Apache-2.0Gid 8835M/wk

aiohttp

Pick aiohttp for an asyncio-only app that also needs a web server or WebSocket client in the same library.

Apache-2.0 AND MITGid 81134M/wk

urllib3

Pick urllib3 for a lower-level sync client with built-in retries on error answers and connection pooling.

MITGid 75376M/wk

Compare httpx with another tool

Get started

Tell your AI assistant

“Use the Python library httpx (pin httpx==0.28.1, Python 3.9+) with one shared httpx.Client or httpx.AsyncClient, set timeout and follow_redirects explicitly, call raise_for_status() on every response, and use httpx.MockTransport in tests.”

  1. Install HTTPX into your project's Python environment.

    pip install httpx

    From github.com/encode/httpx/blob/master/README.md

  2. Make a request and read the answer.

    >>> import httpx
    >>> r = httpx.get('https://www.example.org/')
    >>> r.status_code
    200
    

    From github.com/encode/httpx/blob/master/docs/index.md

  3. In async code, use AsyncClient inside an async with block.

    >>> async with httpx.AsyncClient() as client:
    ...     r = await client.get('https://www.example.com/')
    

    From github.com/encode/httpx/blob/master/docs/async.md

Rules for your agent

Paste into AGENTS.md or CLAUDE.md
## httpx
- Add extras only when the feature is used: `httpx[http2]` for HTTP/2, `httpx[socks]` for SOCKS proxies, `httpx[cli]` for the command-line client, `httpx[brotli]` / `httpx[zstd]` for those decoders.
- Pass query parameters with `params=`. Send form data with `data=`, files with `files=`, JSON with `json=`, and raw bytes or a bytes generator with `content=`.
- Call `raise_for_status()` when non-2xx responses should fail. It returns the response, so `httpx.get(...).raise_for_status().json()` works inline.
- For large downloads, use `httpx.stream(...)` as a context manager with `iter_bytes()`, `iter_text()` or `iter_lines()` instead of reading `r.content`.
- Use `iter_raw()` only when you need the body without gzip, deflate, brotli or zstd decoding.
- Header lookups are case-insensitive, and repeated headers are merged into one comma-separated value. If you need to override the standard encoding behaviour, set `r.encoding`.
- Target Python 3.9+.

Mistakes to avoid

httpx.Client(proxies={"https://": "http://proxy:8080"})
httpx.Client(proxy="http://proxy:8080"), or mounts= with httpx.HTTPTransport(proxy=...) for per-scheme routes

proxies= was removed in 0.28; in our run on 0.28.1 it raised TypeError: unexpected keyword argument 'proxies'.

httpx.AsyncClient(app=app, base_url="http://test") in FastAPI tests
httpx.AsyncClient(transport=httpx.ASGITransport(app=app), base_url="http://test")

app= was removed in 0.28; in our run it raised TypeError: unexpected keyword argument 'app'.

Porting requests code as is and expecting redirects to be followed
Pass follow_redirects=True to the client or to the call

HTTPX returns the 301/302 answer itself; our demo got 301 until follow_redirects=True.

Calling an AI model or slow export service with the default timeout
Set timeout=60.0 (or httpx.Timeout(...)) on the client for slow services

The default raises a timeout after 5 seconds of inactivity; our demo got ReadTimeout with timeout=1.0.

pip install --pre httpx or uv add httpx --pre
pip install httpx==0.28.1

Pre-release 1.0 builds are a redesigned client-and-server toolkit, not a drop-in upgrade of 0.28.

Questions

Can I switch from Requests by changing the import?

Mostly. The interface is close to Requests, but redirects are off by default, timeouts are on, and requests.Session becomes httpx.Client.

Why does my request fail with a timeout when Requests worked?

HTTPX stops after 5 seconds without network activity. Set timeout=30.0 or more, or timeout=None to wait forever.

Does it support HTTP/2?

Yes, after pip install httpx[http2] and http2=True on the client.

Can I use it in a paid app?

Yes. BSD-3-Clause allows commercial and closed-source use; keep the copyright notice if you ship its code.

How do I send requests through a proxy?

Pass proxy="http://..." to the client. The old proxies= argument was removed in 0.28.