{"id":201,"library":"httpx","title":"httpx","description":"Fully featured next-generation HTTP client for Python 3. Provides both synchronous and asynchronous APIs with HTTP/1.1 and HTTP/2 support. Current version is 0.28.1 (December 2024). Pre-1.0: minor version bumps may introduce breaking changes.","status":"active","version":"0.28.1","language":"python","source_language":"en","source_url":"https://github.com/encode/httpx","tags":["http","requests","async","asyncio","http2","client","rest","python"],"install":[{"cmd":"pip install httpx","lang":"bash","label":"Core (HTTP/1.1 only)"},{"cmd":"pip install 'httpx[http2]'","lang":"bash","label":"With HTTP/2 support"},{"cmd":"pip install 'httpx[cli]'","lang":"bash","label":"With command-line client"},{"cmd":"pip install 'httpx[brotli]'","lang":"bash","label":"With Brotli decoding"},{"cmd":"pip install 'httpx[zstd]'","lang":"bash","label":"With Zstandard decoding"}],"dependencies":[{"reason":"Required to enable HTTP/2. Not included by default. Pass http2=True to Client or AsyncClient after installing.","package":"httpx[http2]","optional":true},{"reason":"Installs the httpx command-line client. Optional development/debugging tool.","package":"httpx[cli]","optional":true},{"reason":"Enables Brotli response content decoding via brotlipy.","package":"httpx[brotli]","optional":true},{"reason":"Enables Zstandard (zstd) response content decoding via the zstandard package.","package":"httpx[zstd]","optional":true}],"imports":[{"note":"Top-level module import. All public symbols (Client, AsyncClient, Request, Response, etc.) are available under httpx.*","symbol":"httpx","correct":"import httpx"},{"note":"Always use Client as a context manager (with statement) to ensure connections are properly closed and pooled.","wrong":"client = httpx.Client()\nr = client.get('https://example.com')\n# never call client.close() manually forgotten","symbol":"httpx.Client","correct":"with httpx.Client() as client:\n    r = client.get('https://example.com')"},{"note":"Always use AsyncClient as an async context manager. Failing to do so leaks connections. Do not instantiate a new AsyncClient per request — reuse one instance.","wrong":"client = httpx.AsyncClient()\nr = await client.get('https://example.com')","symbol":"httpx.AsyncClient","correct":"async with httpx.AsyncClient() as client:\n    r = await client.get('https://example.com')"},{"note":"Passing a plain number sets all timeout phases equally. Use httpx.Timeout() for granular control of connect, read, write, and pool timeouts.","wrong":"httpx.Client(timeout=5)","symbol":"httpx.Timeout","correct":"httpx.Client(timeout=httpx.Timeout(5.0, connect=2.0))"},{"note":"Auth can be a (user, pass) tuple or an httpx.Auth subclass. NetRC auth is no longer automatic; use httpx.NetRCAuth() explicitly.","symbol":"httpx.BasicAuth / httpx.Auth","correct":"httpx.Client(auth=('user', 'pass'))\n# or\nhttpx.Client(auth=httpx.BasicAuth('user', 'pass'))"}],"quickstart":{"code":"import httpx\n\n# One-off request (new connection each time — fine for scripts)\nr = httpx.get('https://httpbin.org/get', timeout=10.0)\nr.raise_for_status()\nprint(r.status_code)       # 200\nprint(r.json())            # parsed JSON body\n\n# Recommended: reuse a Client for multiple requests (connection pooling)\nwith httpx.Client(base_url='https://httpbin.org', timeout=10.0) as client:\n    resp = client.get('/get', params={'key': 'value'})\n    resp.raise_for_status()\n    print(resp.json())\n\n# Async variant\nimport asyncio\n\nasync def main():\n    async with httpx.AsyncClient(base_url='https://httpbin.org', timeout=10.0) as client:\n        resp = await client.get('/get')\n        resp.raise_for_status()\n        print(resp.json())\n\nasyncio.run(main())","lang":"python","description":"Minimal sync and async HTTP GET requests using httpx 0.28.x. Uses Client/AsyncClient as context managers for proper connection management."},"warnings":[{"fix":"Use proxy='http://...' for a single proxy, or mounts={'https://': httpx.HTTPTransport(proxy='...')} for per-scheme configuration.","message":"proxies= argument was removed in 0.28.0. Using it raises TypeError.","severity":"breaking","affected_versions":">= 0.28.0"},{"fix":"Use transport=httpx.WSGITransport(app=app) or transport=httpx.ASGITransport(app=app) explicitly.","message":"app= shortcut argument was removed in 0.28.0. It was deprecated in 0.27.0.","severity":"breaking","affected_versions":">= 0.28.0"},{"fix":"Pass follow_redirects=True per-request or at the Client level: httpx.Client(follow_redirects=True).","message":"Redirects are NOT followed by default (changed in 0.20.0). Requests that previously auto-redirected now return the 3xx response directly.","severity":"breaking","affected_versions":">= 0.20.0"},{"fix":"Build an ssl.SSLContext manually and pass it via verify=ssl_context. See https://www.python-httpx.org/advanced/ssl/","message":"verify='path/to/ca-bundle' (string) and cert=('cert', 'key') arguments are deprecated in 0.28.0 and will raise DeprecationWarning.","severity":"deprecated","affected_versions":">= 0.28.0"},{"fix":"Pin with httpx>=0.28.1,<0.29 in requirements. Review the CHANGELOG before upgrading.","message":"httpx is pre-1.0. Minor version bumps (e.g. 0.27 → 0.28) can and do introduce breaking changes. The maintainers recommend pinning the minor version.","severity":"gotcha","affected_versions":"all"},{"fix":"pip install 'httpx[http2]' then pass http2=True: httpx.Client(http2=True)","message":"HTTP/2 is disabled by default. Installing httpx alone does not enable it.","severity":"gotcha","affected_versions":"all"},{"fix":"Use httpx.Client() or httpx.AsyncClient() as a context manager for connection pooling, keep-alive, and shared configuration.","message":"Top-level functions (httpx.get, httpx.post, etc.) open a new TCP connection on every call. For more than one request to the same host this is inefficient.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'-1.0':30 '0.28.1':26 '2024':28 '3':11 'api':17 'async':40 'asynchron':16 'asyncio':41 'break':36 'bump':33 'chang':37 'client':8,43 'current':23 'decemb':27 'featur':3 'fulli':2 'generat':6 'http':7,38 'http/1.1':19 'http/2':21 'http2':42 'httpx':1 'introduc':35 'may':34 'minor':31 'next':5 'next-gener':4 'pre':29 'provid':12 'python':10,45 'request':39 'rest':44 'support':22 'synchron':14 'version':24,32","created_at":"2026-03-25T18:28:23.007916+00:00","updated_at":"2026-04-16T15:37:40.832615+00:00","problems":[{"fix":"Install the library using pip: `pip install httpx`","cause":"The 'httpx' library is not installed in your current Python environment.","error":"ModuleNotFoundError: No module named 'httpx'"},{"fix":"Upgrade the dependent library to a version compatible with `httpx` 0.28.x, or configure proxies using environment variables (HTTP_PROXY, HTTPS_PROXY), or downgrade `httpx` to a version prior to 0.28.0, such as `pip install httpx==0.27.2`.","cause":"In `httpx` versions 0.28.0 and later, the `proxies` argument was removed from `AsyncClient`'s constructor, leading to this error if older code or dependent libraries (e.g., `openai`) still try to pass it.","error":"TypeError: AsyncClient.__init__() got an unexpected keyword argument 'proxies'"},{"fix":"Ensure that all calls to `AsyncClient` methods are `await`ed and that the code runs within an `async` function and an `asyncio` event loop: `async with httpx.AsyncClient() as client: await client.get('https://example.com')`","cause":"You are trying to call a synchronous request method (e.g., `client.get()`) on an `httpx.AsyncClient` instance without awaiting it, or within a synchronous context.","error":"RuntimeError: Attempted to send an sync request with an AsyncClient instance."},{"fix":"Increase the timeout value when making the request or initializing the client: `httpx.get('https://example.com', timeout=10.0)` or `client = httpx.Client(timeout=httpx.Timeout(5.0, connect=10.0, read=20.0))`.","cause":"A network operation (connection, read, or write) took longer than the configured timeout duration.","error":"httpx.TimeoutException"},{"fix":"Ensure the URL includes a valid scheme: `httpx.get('https://www.example.com/')` instead of `httpx.get('www.example.com/')`.","cause":"The URL provided is missing a protocol scheme (like 'http://' or 'https://') or uses a scheme not supported by `httpx`.","error":"httpx.UnsupportedProtocol"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":77,"quickstart_tag":"verified","pypi_latest":"0.28.1","cli_name":"","cli_version":null,"type":"library","homepage":"https://www.python-httpx.org","github":"https://github.com/encode/httpx","docs":"https://www.python-httpx.org","changelog":"https://github.com/encode/httpx/blob/master/CHANGELOG.md","pypi":"https://pypi.org/project/httpx/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-27","last_verified":"2026-08-26","next_check":"2026-07-27","install_tag":"verified"}}