# httpx — card for AI agents

Modern Python HTTP client with async support, replacing the standard requests library.

Category: HTTP clients and networking · PyPI package `httpx` · latest version 0.28.1 (checked 2026-11-01)
Install: `pip install httpx`
License: BSD (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (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+.

## What it is
- HTTPX describes itself as "a next-generation HTTP client for Python". It is installed with `pip install httpx` and is BSD-3-Clause licensed. The GitHub repository was created on 2019-04-04. It speaks HTTP/1.1 and HTTP/2 and has both sync and async APIs.
- The project credits `requests` for "the API layout that much of this work follows" and `urllib3` for design inspiration around lower-level networking. In practice `httpx.get(...)` and `httpx.post(...)` return a response with `status_code`, `headers`, `text` and `json()`. The network transport is a separate package, `httpcore`. HTTP/2, SOCKS proxies, the command-line client and brotli/zstd decoding are optional extras.
- The interface is synchronous as standard, with async available when needed. It can also send requests straight into a WSGI or ASGI application instead of over the network. It requires Python 3.9+.

## Caveats
- Intermittent ReadError reported under heavy traffic: Miguel Mendez reports random crashes ending in `httpx.ReadError` 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 (`h2`) and SOCKS proxy support (`socksio`) as optional, installed with `httpx[http2]` and `httpx[socks]`. A plain `pip install httpx` 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 `httpx[brotli,zstd]` extras. The site's dependency list names `brotli` or `brotlicffi` for brotli decoding. The quickstart page instead says "If brotlipy is installed".
- Repeated headers come back merged: When a response carries the same header more than once, `r.headers` returns one comma-separated value rather than separate entries.

## Numbers (AgentGid data)
- Gid Score: 77.7 (#140 of all tools, 8 of 126 in its category)
- Used in 280 public projects set up for AI coding agents (4.5%)
- Downloads last week: 198,250,800 (as of 2026-11-24), +15.5% over 4 weeks
- GitHub stars: 15,844 (as of 2026-11-24)
- Last push: 2026-11-16

## Often used with
Pydantic 56.8%, Uvicorn 52.5%, python-dotenv 50.4%, FastAPI 48.6%, Model Context Protocol SDK (Python) 43.9%, PyYAML 32.9%

## Checked alternatives (same job)
- Requests: https://agentgid.com/tools/requests-py/agent.md
- aiohttp: https://agentgid.com/tools/aiohttp/agent.md
- urllib3: https://agentgid.com/tools/urllib3/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/httpx/
- Homepage: https://github.com/encode/httpx
- Repository: https://github.com/encode/httpx
- Source: https://github.com/encode/httpx#readme
- Source: https://github.com/encode/httpx
- Source: https://github.com/encode/httpx/releases
- Source: https://www.python-httpx.org/
- Source: https://www.python-httpx.org/quickstart/


## HTTPX: call web services from Python, sync or async

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.

### Where to use 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: An app that sends many requests to one AI service turns on HTTP/2, so they share one connection. (idea, not from the official pages)

### How to start
- Install HTTPX into your project's Python environment.

```
pip install httpx
```

- Make a request and read the answer.

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

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

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


### License
Free to use, also in paid and closed-source products, under the BSD-3-Clause license. If you ship its code, keep its copyright notice; you may not use the project's name to promote your product without permission.

### Good to know
- Unlike Requests, it does not follow redirects unless you ask, so a moved page comes back as a 301 or 302 answer.
- It gives up after 5 seconds of no network activity by default; slow services, such as AI models, need a longer timeout.
- Its own retries cover only failed connections; for retrying busy or error answers the docs point to a general retry tool such as tenacity.
- The last stable release is 0.28.1 from December 2024. Newer 1.0 test builds on the package index have a different design, so pin the version.
- HTTP/2 is off unless you install the http2 extra and turn it on.

Checked 2026-11-11 against: https://github.com/encode/httpx/blob/master/docs/index.md, https://github.com/encode/httpx/blob/master/docs/async.md, https://www.python-httpx.org/, https://www.python-httpx.org/quickstart/, https://www.python-httpx.org/async/, https://www.python-httpx.org/compatibility/, https://www.python-httpx.org/advanced/clients/, https://www.python-httpx.org/advanced/timeouts/, https://www.python-httpx.org/advanced/transports/, https://www.python-httpx.org/advanced/proxies/, https://www.python-httpx.org/http2/, https://github.com/encode/httpx/blob/master/README.md, https://github.com/encode/httpx/blob/master/CHANGELOG.md, https://github.com/encode/httpx/blob/master/LICENSE.md, https://pypi.org/pypi/httpx/json, https://pypi.org/pypi/httpx/1.0.dev6/json

### Mistakes to avoid
- Don't: httpx.Client(proxies={"https://": "http://proxy:8080"}) → Do: 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'.)
- Don't: httpx.AsyncClient(app=app, base_url="http://test") in FastAPI tests → Do: 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'.)
- Don't: Porting requests code as is and expecting redirects to be followed → Do: 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.)
- Don't: Calling an AI model or slow export service with the default timeout → Do: 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.)
- Don't: pip install --pre httpx or uv add httpx --pre → Do: 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.

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
