Quick Start
Installation
Install httpxr from PyPI:
To also install the optional CLI:
Coming from httpx?
httpxr is a drop-in replacement. In most cases you just need to change your import:
See the full Migration Guide for details.
Your First Request
Sync
The simplest way to make an HTTP request:
import httpxr
response = httpxr.get("https://httpbin.org/get")
print(response.status_code) # 200
print(response.json()) # {...}
Async
For async code, use AsyncClient:
import httpxr
import asyncio
async def main():
async with httpxr.AsyncClient() as client:
response = await client.get("https://httpbin.org/get")
print(response.json())
asyncio.run(main())
Using a Client
For production code, always use a Client (or AsyncClient) as a context manager.
This enables connection pooling and keepalive for much better performance:
Convenience Functions
httpxr provides top-level convenience functions that create a one-off client per call. Great for scripts and quick tasks:
import httpxr
# GET
r = httpxr.get("https://httpbin.org/get")
# POST with JSON
r = httpxr.post("https://httpbin.org/post", json={"key": "value"})
# POST with raw bytes
r = httpxr.post("https://httpbin.org/post", content=b"Hello!")
# PUT
r = httpxr.put("https://httpbin.org/put", content=b"updated")
# PATCH
r = httpxr.patch("https://httpbin.org/patch", content=b"partial")
# DELETE
r = httpxr.delete("https://httpbin.org/delete")
# HEAD
r = httpxr.head("https://httpbin.org/get")
# OPTIONS
r = httpxr.options("https://httpbin.org/get")
Working with Responses
response = httpxr.get("https://httpbin.org/get")
# Status
response.status_code # 200
response.reason_phrase # "OK"
response.is_success # True
# Content
response.text # Response body as string
response.content # Response body as bytes
response.json() # Parse JSON body as dict
# Metadata
response.url # URL object
response.headers # Headers object
response.encoding # "utf-8"
response.elapsed # Request duration in seconds
response.http_version # "HTTP/1.1"
What's Next?
- Clients — Client lifecycle, base URLs, HTTP/2
- Authentication — BasicAuth, DigestAuth, custom auth
- Extensions —
gather(),paginate(), raw API - Error Handling — Exception hierarchy