A utility for mocking out the Python HTTPX and HTTP Core libraries.
Project Links
Meta
Author: Jonas Lundberg
Requires Python: >=3.8
Classifiers
Development Status
- 5 - Production/Stable
Intended Audience
- Developers
License
- OSI Approved :: BSD License
Operating System
- OS Independent
Programming Language
- Python
- Python :: 3
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
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.
0.22.0
Dec 19, 2024
0.21.1
Mar 27, 2024
0.21.0
Mar 19, 2024
0.20.2
Jul 20, 2023
0.20.1
Nov 18, 2022
0.20.0
Sep 16, 2022
0.19.3
Sep 14, 2022
0.19.2
Feb 03, 2022
0.19.1
Jan 10, 2022
0.19.0
Nov 15, 2021
0.18.2
Oct 22, 2021
0.18.1
Oct 20, 2021
0.18.0
Oct 14, 2021
0.18.0b0
Sep 15, 2021
0.17.1
Jul 05, 2021
0.17.0
Apr 27, 2021
0.16.3
Dec 14, 2020
0.16.2
Nov 26, 2020
0.16.1
Nov 16, 2020
0.16.0
Nov 13, 2020
0.15.1
Nov 10, 2020
0.15.0
Nov 09, 2020
0.14.0
Oct 15, 2020
0.13.0
Sep 30, 2020
0.12.1
Aug 21, 2020
0.12.0
Aug 17, 2020
0.11.3
Aug 13, 2020
0.11.2
Jun 25, 2020
0.11.1
Jun 01, 2020
0.11.0
May 29, 2020
0.10.1
Mar 11, 2020
0.10.0
Jan 30, 2020
0.9.0
Jan 22, 2020
0.8.3
Jan 10, 2020
0.8.2
Jan 07, 2020
0.8.1
Dec 09, 2019
0.8
Nov 27, 2019
0.7.4
Nov 24, 2019
0.7.3
Nov 21, 2019
0.7.2
Nov 21, 2019
0.7.1
Nov 20, 2019
0.7
Nov 19, 2019
0.6
Nov 18, 2019
0.5
Nov 18, 2019
0.4
Nov 16, 2019
0.3.1
Nov 16, 2019
Wheel compatibility matrix
Files in release
Extras:
None
Dependencies:
httpx
(>=0.25.0)
