API Reference
respx
A utility for mocking HTTPX requests in tests, supporting routes, patterns, and assertions.
Official Documentation ↗CompatibilityThis documentation covers version
v0.21. Check the official docs for the latest API surface.Installation
pip
pip install respxMethods
No methods match this filter.
respx patches HTTPX transports so requests return mocked responses without a network.
Key Features
- Route-based HTTPX mocking
- Side effects and response sequences
- Call assertions and pass-through
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
API reference evidence
Fetched from official sources on 2026-11-08T17:50:10+08:00 via WebFetch https://raw.githubusercontent.com/lundberg/respx/master/docs/api.md.
respx.mock→ signature from https://raw.githubusercontent.com/lundberg/respx/master/docs/api.md; official text: “respx.mock(assert_all_mocked=True, assert_all_called=True, base_url=None)”respx.get→ signature from https://raw.githubusercontent.com/lundberg/respx/master/docs/api.md; official text: “respx.get(url, name=None, **lookups)”respx.post→ signature from https://raw.githubusercontent.com/lundberg/respx/master/docs/api.md; official text: “respx.post(…)”
FAQ
- Why is a real request going out?
- A URL not matched by any route is passed through by default; set assert_all_called and explicit routes so gaps are visible.
- How do I return different responses over time?
- Use side_effect with a list or callable so successive calls return a sequence.
- Does it work with other clients?
- No. respx targets HTTPX. Use responses for requests or a similar tool for other libraries.
Report a problem with this API docOpens a pre-filled issue on GitHub.