Metadata-Version: 2.1 Name: respx Version: 0.23.1 Summary: A utility for mocking out the Python HTTPX and HTTP Core libraries. Home-page: https://lundberg.github.io/respx/ Author: Jonas Lundberg Author-email: jonas@5monkeys.se License: BSD-3-Clause Project-URL: GitHub, https://github.com/lundberg/respx Project-URL: Changelog, https://github.com/lundberg/respx/blob/master/CHANGELOG.md Project-URL: Issues, https://github.com/lundberg/respx/issues Keywords: httpx,httpcore,mock,responses,requests,async,http Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 Classifier: Programming Language :: Python :: 3.13 Classifier: Programming Language :: Python :: 3.14 Requires-Python: >=3.8 Description-Content-Type: text/markdown License-File: LICENSE.md Requires-Dist: httpx>=0.25.0
RESPX - Mock HTTPX with awesome request patterns and response side effects.
--- [](https://github.com/lundberg/respx/actions/workflows/test.yml) [](https://codecov.io/gh/lundberg/respx) [](https://pypi.org/project/respx/) [](https://pypi.org/project/respx/) [](https://pypi.org/project/respx/) ## Documentation Full documentation is available at [lundberg.github.io/respx](https://lundberg.github.io/respx/) ## QuickStart RESPX is a simple, _yet powerful_, utility for mocking out the [HTTPX](https://www.python-httpx.org/), _and [HTTP Core](https://www.encode.io/httpcore/)_, libraries. Start by [patching](https://lundberg.github.io/respx/guide/#mock-httpx) `HTTPX`, using `respx.mock`, then add request [routes](https://lundberg.github.io/respx/guide/#routing-requests) to mock [responses](https://lundberg.github.io/respx/guide/#mocking-responses). ```python 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](https://lundberg.github.io/respx/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](https://lundberg.github.io/respx/api/#configuration). ```python 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: ```console $ pip install respx ``` Requires Python 3.8+ and HTTPX 0.25+. See [Changelog](https://github.com/lundberg/respx/blob/master/CHANGELOG.md) for older HTTPX compatibility.