respx is a powerful and flexible utility for mocking out the Python HTTPX and HTTP Core libraries, essential for writing fast and reliable tests for applications that make HTTP requests. It allows developers to intercept HTTP requests and provide predefined responses. The library is actively maintained with frequent releases, currently at version 0.23.1, often updating to align with new HTTPX versions.
pip install respxVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use the `@respx.mock` decorator to intercept an HTTPX GET request. It defines a mock response for a specific URL, then performs an HTTPX request that transparently receives the mocked data. Finally, it asserts the response and verifies that the mock was called.
Upgrade to Python 3.8+ or pin `respx` version to `<0.22.0`.
Update code to catch `AttributeError` or ensure a call/response exists before accessing these properties. For example, check `if respx.calls.called:` before `respx.calls.last.response`.
Upgrade to `respx` version 0.23.1 or later to ensure correct `params` pattern matching.
Upgrade to `respx` version 0.23.0 or later to ensure robust `ANY` pattern matching in multi-item contexts.
Upgrade to `respx` version 0.21.0 or later to use the `files` pattern for easier matching of file uploads.
Upgrade to `respx` version 0.19.3 or later for improved compatibility and stability when using the decorator with `pytest` fixtures.