API Reference

httpx

Next-generation HTTP client for Python with sync and async APIs, HTTP/2, and timeouts.

Official Documentation ↗
CompatibilityThis documentation covers version v0.27. Check the official docs for the latest API surface.

Installation

pippip install httpx

Methods

httpx is a fully featured HTTP client for Python, providing sync and async APIs, HTTP/1.1 and HTTP/2 support, connection pooling, timeouts, and streaming. It is a modern, more capable alternative to Requests.

Key Features

  • Sync and async: One API, two execution models
  • HTTP/2: Multiplexed connections for lower latency
  • Streaming: Iterative reading of large responses
  • Timeouts: Connect, read, write, and pool timeouts
  • Auth: Basic, digest, and custom auth flows

Errors

The official API reference declares the following error types:

Security

Official security statements captured from the package documentation:

  • verify=True 默认启用默认 CA 证书校验;可传 ssl.SSLContext 自定义 — “verify - (optional) Either True to use an SSL context with the default CA bundle, False to disable verification, or an instance of ssl.SSLContext to use a custom context.” (source: https://www.python-httpx.org/api/#client, fetched 2026-11-08T16:03:08.4363995+08:00)

API reference evidence

Fetched from official sources on 2026-11-08T16:03:08.4363995+08:00 via WebFetch 官方 API 页面(异常另抓 https://www.python-httpx.org/exceptions/).

  • httpx.get → signature from https://www.python-httpx.org/api/#helper-functions; official text: “httpx.get(url, *, params=None, headers=None, cookies=None, auth=None, proxy=None, follow_redirects=False, verify=True, timeout=Timeout(timeout=5.0), trust_env=True)”
  • Client → signature from https://www.python-httpx.org/api/#client; official text: “class httpx.Client(*, auth=None, params=None, headers=None, cookies=None, verify=True, cert=None, trust_env=True, http1=True, http2=False, proxy=None, mounts=None, timeout=Timeout(timeout=5.0), follow_redirects=False, li”
  • AsyncClient → signature from https://www.python-httpx.org/api/#asyncclient; official text: “class httpx.AsyncClient(*, auth=None, params=None, headers=None, cookies=None, verify=True, cert=None, http1=True, http2=False, proxy=None, mounts=None, timeout=Timeout(timeout=5.0), follow_redirects=False, limits=Limits”
  • HTTP/2 → signature from https://www.python-httpx.org/api/#client; official text: “http2 - (optional) A boolean indicating if HTTP/2 support should be enabled. Defaults to False.”
  • stream → signature from https://www.python-httpx.org/api/#helper-functions; official text: “httpx.stream(method, url, *, params=None, content=None, data=None, files=None, json=None, headers=None, cookies=None, auth=None, proxy=None, timeout=Timeout(timeout=5.0), follow_redirects=False, verify=True, trust_env=Tr”

FAQ

How does httpx compare to Requests?
httpx offers both sync and async APIs, HTTP/2 support, and stricter timeouts, with a Requests-compatible sync API. Requests is sync-only and HTTP/1.1. httpx is the modern choice, especially for async frameworks.
When should I use AsyncClient?
Use AsyncClient inside async code (asyncio, FastAPI, Starlette) to make many concurrent requests without blocking the event loop. For simple blocking scripts, the sync Client or module functions are simpler.
Does httpx support retries and auth?
httpx has built-in basic and digest auth and a transport API for custom retry logic. For automatic retries, use a custom transport or a library like httpx-retries, since httpx does not retry by default.