respx
RESPX is a Python library that mocks HTTPX HTTP client requests for testing purposes. It lets developers define request patterns and mock responses without making real network calls, integrating seamlessly with pytest.
Key facts
Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.
| Field | Value |
|---|---|
| Repository | lundberg/respx |
| Owner | lundberg |
| Primary language | Python |
| License | BSD-3-Clause — OSI-approved |
| Stars | 814 |
| Forks | 61 |
| Open issues | 24 |
| Latest release | 0.23.1 (2026-04-08) |
| Last updated | 2026-06-19 |
| Source | https://github.com/lundberg/respx |
What respx is
RESPX patches HTTPX and HTTP Core libraries to intercept requests, providing a routing system for matching request patterns and returning mock responses. It offers both decorator and pytest fixture approaches, supporting configuration via pytest markers.
Get the respx source
Clone the repository and explore it locally.
git clone https://github.com/lundberg/respx.gitcd respx# follow the project's README for install & configurationNeed it deployed, integrated, or customized instead? DEV.co ships production installs.
Best use cases
Implementation considerations
- Confirm HTTPX version compatibility: requires HTTPX 0.25+ and Python 3.8+. Check changelog for older version support.
- Choose between decorator (@respx.mock) and pytest fixture (respx_mock) based on test structure; fixtures are generally preferred for pytest suites.
- Define routes with sufficient specificity to avoid unintended matches; overly broad patterns can mask bugs in request construction.
- For async test coroutines, ensure mock context is properly entered and exited; pytest-asyncio integration may require explicit async fixture scope.
- Monitor response side effects (headers, cookies, redirects) if your code relies on them; mock responses may need explicit configuration.
When to avoid it — and what to weigh
- Testing actual network behavior — RESPX mocks requests entirely; it cannot validate real SSL/TLS handshakes, connection pooling, or timeout behavior of actual HTTP stacks.
- Non-HTTPX HTTP clients — RESPX only patches HTTPX and HTTP Core. If your codebase uses requests, urllib3, or other HTTP libraries, you'll need alternative mocking strategies.
- Production monitoring or traffic capture — RESPX is a testing utility only. It is not suitable for recording real traffic, profiling live endpoints, or production request interception.
- Complex async/sync hybrid codebases without careful setup — While RESPX supports both async and sync, incorrect mock scope or fixture configuration can lead to race conditions or leaked mocks across tests.
License & commercial use
BSD-3-Clause license permits commercial use, modification, and distribution provided original copyright and license text are included and the name is not used for endorsement.
BSD-3-Clause is a permissive OSI-approved license. Commercial use is permitted under its terms. No proprietary restrictions, but include license text in distributions and respect the liability disclaimers.
DEV.co evaluation signals
Editorial assessment — not user reviews. Directional, with an explicit confidence level.
| Signal | Assessment |
|---|---|
| Maintenance | Active |
| Documentation | Strong |
| License clarity | Clear |
| Deployment complexity | Low |
| DEV.co fit | Strong |
| Assessment confidence | High |
RESPX is a testing mock library and does not handle real credentials or network security. Ensure mock responses do not accidentally log sensitive data in test output. No inherent vulnerabilities disclosed; review CHANGELOG for any past security patches. Mocking also prevents validation of real SSL/TLS certificate chains during testing—ensure separate security validation in integration or staging environments.
Alternatives to consider
pytest-httpserver
Spins up a real local HTTP server for testing. Better for validating actual HTTP server behavior but slower and more complex than mocking.
responses (or responses-mock)
Mocks the requests library instead of HTTPX. Choose if your codebase uses requests rather than httpx.
unittest.mock + monkeypatch
Bare-bones manual patching without respx's routing DSL. Lower-level control but more verbose and error-prone for HTTP-heavy test suites.
Build on respx with DEV.co software developers
Our engineers can guide you through mocking strategies, test suite design, and integration with your CI/CD pipeline. Let's discuss your testing needs.
Talk to DEV.coRelated open-source tools
Surfaced by semantic similarity across the DEV.co open-source index.
Related on DEV.co
Explore the category and the services that help you build with it.
respx FAQ
Does RESPX work with async httpx code?
Can I mock websocket or streaming responses?
How do I ensure mocks don't leak between tests?
What if I need to mock multiple independent mock instances?
Software development & web development with DEV.co
DEV.co helps companies turn open-source tools like respx into production software. Our software development services cover the full lifecycle — architecture, web development, integration, and maintenance — delivered by software developers and web developers who ship. Engage our software development agency to implement or customize it for your open-source testing stack.
Need Help Implementing RESPX?
Our engineers can guide you through mocking strategies, test suite design, and integration with your CI/CD pipeline. Let's discuss your testing needs.