RESPX - Mock HTTPX with awesome request patterns and response side effects.
Documentation
Full documentation is available at lundberg.github.io/respx
QuickStart
RESPX is a simple, yet powerful, utility for mocking out the HTTPX, and HTTP Core, libraries.
Start by patching HTTPX, using
respx.mock, then add request
routes to mock
responses.
import httpx
import respx
from httpx import Response
@respx.mock
def test_example():
my_route = respx.get("https://example.org/").mock(return_value=Response(204))
response = httpx.get("https://example.org/")
assert my_route.called
assert response.status_code == 204
Read the User Guide for a complete walk-through.
pytest + httpx
For a neater pytest experience, RESPX includes a respx_mock fixture for easy
HTTPX mocking, along with an optional respx marker to fine-tune the mock
settings.
import httpx
import pytest
def test_default(respx_mock):
respx_mock.get("https://foo.bar/").mock(return_value=httpx.Response(204))
response = httpx.get("https://foo.bar/")
assert response.status_code == 204
@pytest.mark.respx(base_url="https://foo.bar")
def test_with_marker(respx_mock):
respx_mock.get("/baz/").mock(return_value=httpx.Response(204))
response = httpx.get("https://foo.bar/baz/")
assert response.status_code == 204
Installation
Install with pip:
$ pip install respx
Requires Python 3.8+ and HTTPX 0.25+. See Changelog for older HTTPX compatibility.
Release files for respx 0.23.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| respx-0.23.1.tar.gz | 29.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| respx-0.23.1-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 54.8 kB
Release files / respx-0.23.1.tar.gz
| Download URL | respx-0.23.1.tar.gz |
|---|---|
| Size | 29.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
242dcc6ce6b5b9bf621f5870c82a63997e8e82bc7c947f9ffe272b8f3dd5a780
|
|
BLAKE2b-256 checksum How to use checksums |
43984e55c9c486404ec12373708d015ebce157966965a5ebe7f28ff2c784d41b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.3
|
Release files / respx-0.23.1-py2.py3-none-any.whl
| Download URL | respx-0.23.1-py2.py3-none-any.whl |
|---|---|
| Size | 25.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
b18004b029935384bccfa6d7d9d74b4ec9af73a081cc28600fffc0447f4b8c1a
|
|
BLAKE2b-256 checksum How to use checksums |
1d4a221da6ca167db45693d8d26c7dc79ccfc978a440251bf6721c9aaf251ac0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.3
|