Registry / testing / respx
library0.23.1pypypi✓ verified 27d ago

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 respx
INSTALL
IMPORT
SIG · RESPX
R
respx
testingpythonv0.23.1
Install
2.2s avg
Import
645ms
Disk
20MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.23.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.688s · 22.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 2.2s · import 0.602s · 23MB
20MB installed
● package 20MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

respx
import respx
The main library module.
Response
from httpx import Response
Used for creating mock responses, typically imported directly from httpx.
mock (decorator)
@respx.mock
Common decorator for mocking HTTP requests within a test function.
ANY
from respx import ANY
Wildcard pattern matcher for request details.

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.

import respx import httpx from httpx import Response @respx.mock def test_mocked_api_call(): # Define a mock response for a GET request to a specific URL respx.get("https://api.example.com/users/1")\ .mock(return_value=Response(200, json={ "id": 1, "name": "Jane Doe", "email": "jane.doe@example.com" })) # Make the actual HTTPX request, which will be intercepted by respx response = httpx.get("https://api.example.com/users/1") # Assertions to verify the mocked response assert response.status_code == 200 assert response.json()["name"] == "Jane Doe" print(f"Mocked response received: {response.json()}") # Verify that the mock was called assert respx.calls.call_count == 1 assert respx.calls.called if __name__ == '__main__': print("Running mocked API call example...") test_mocked_api_call() print("Example finished successfully.")
Debug
Known issues
breakingrespx dropped support for Python 3.7 in version 0.22.0 to align with HTTPX 0.25.0. Projects using Python 3.7 must pin respx to <0.22.0.
fix
Upgrade to Python 3.8+ or pin `respx` version to `<0.22.0`.
affects: >=0.22.0
breakingSince version 0.20.0, `Call.response` and `CallList.last` now raise an `AttributeError` (or similar for missing calls) instead of returning `None` if a response or call is not found. This changes the expected behavior for type-hinted code or code implicitly handling `None`.
fix
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`.
affects: >=0.20.0
gotchaA regression in version 0.23.0 caused `params` pattern matching to stop working under some conditions, especially with `ANY` in multi-item patterns. This was fixed in 0.23.1.
fix
Upgrade to `respx` version 0.23.1 or later to ensure correct `params` pattern matching.
affects: 0.23.0
gotchaPrior to version 0.23.0, the `ANY` wildcard in `MultiItems` patterns (used for headers, params, or data with multiple values) might not have been handled properly, potentially leading to unexpected mismatches.
fix
Upgrade to `respx` version 0.23.0 or later to ensure robust `ANY` pattern matching in multi-item contexts.
affects: <0.23.0
gotchaBefore version 0.21.0, direct matching on `files` (multipart/form-data uploads) was not officially supported and might have required custom workarounds. The `files` pattern was added in 0.21.0.
fix
Upgrade to `respx` version 0.21.0 or later to use the `files` pattern for easier matching of file uploads.
affects: <0.21.0
gotchaCombining the `@respx.mock` decorator with `pytest` fixtures prior to version 0.19.3 could sometimes lead to unexpected behavior or conflicts, such as the mock not being active or pytest's function wrapping being incorrect.
fix
Upgrade to `respx` version 0.19.3 or later for improved compatibility and stability when using the decorator with `pytest` fixtures.
affects: <0.19.3
Upgrade
Version history
0.23.1latest on PyPI · released Apr 8, 2026
Audit
Dependencies
httpxrequiredrespx is designed to mock httpx; httpx is a required runtime dependency (>=0.23.0,<1.0.0).
Agent activity
20 hits · last 30 days
node
18
Amazon
1
Resources
respx — pip install respx · libregistry