<p align="center">
<a href="https://lundberg.github.io/respx/"><img width="350" height="208" src="https://raw.githubusercontent.com/lundberg/respx/master/docs/img/respx.png" alt='RESPX'></a>
</p>
<p align="center">
<strong>RESPX</strong> <em>- Mock HTTPX with awesome request patterns and response side effects.</em>
</p>
---
[![tests](https://img.shields.io/github/actions/workflow/status/lundberg/respx/test.yml?branch=master&label=tests&logo=github&logoColor=white&style=for-the-badge)](https://github.com/lundberg/respx/actions/workflows/test.yml)
[![codecov](https://img.shields.io/codecov/c/github/lundberg/respx?logo=codecov&logoColor=white&style=for-the-badge)](https://codecov.io/gh/lundberg/respx)
[![PyPi Version](https://img.shields.io/pypi/v/respx?logo=pypi&logoColor=white&style=for-the-badge)](https://pypi.org/project/respx/)
[![Python Versions](https://img.shields.io/pypi/pyversions/respx?logo=python&logoColor=white&style=for-the-badge)](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.7+ and HTTPX 0.21+. See
[Changelog](https://github.com/lundberg/respx/blob/master/CHANGELOG.md) for older HTTPX
compatibility.
Raw data
{
"_id": null,
"home_page": "https://lundberg.github.io/respx/",
"name": "respx",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "httpx, httpcore, mock, responses, requests, async, http",
"author": "Jonas Lundberg",
"author_email": "jonas@5monkeys.se",
"download_url": "https://files.pythonhosted.org/packages/fd/72/979e475ade69bcbb18288604aacbdc77b44b3bd1133e2c16660282a9f4b8/respx-0.21.1.tar.gz",
"platform": null,
"description": "<p align=\"center\">\n <a href=\"https://lundberg.github.io/respx/\"><img width=\"350\" height=\"208\" src=\"https://raw.githubusercontent.com/lundberg/respx/master/docs/img/respx.png\" alt='RESPX'></a>\n</p>\n<p align=\"center\">\n <strong>RESPX</strong> <em>- Mock HTTPX with awesome request patterns and response side effects.</em>\n</p>\n\n---\n\n[![tests](https://img.shields.io/github/actions/workflow/status/lundberg/respx/test.yml?branch=master&label=tests&logo=github&logoColor=white&style=for-the-badge)](https://github.com/lundberg/respx/actions/workflows/test.yml)\n[![codecov](https://img.shields.io/codecov/c/github/lundberg/respx?logo=codecov&logoColor=white&style=for-the-badge)](https://codecov.io/gh/lundberg/respx)\n[![PyPi Version](https://img.shields.io/pypi/v/respx?logo=pypi&logoColor=white&style=for-the-badge)](https://pypi.org/project/respx/)\n[![Python Versions](https://img.shields.io/pypi/pyversions/respx?logo=python&logoColor=white&style=for-the-badge)](https://pypi.org/project/respx/)\n\n## Documentation\n\nFull documentation is available at\n[lundberg.github.io/respx](https://lundberg.github.io/respx/)\n\n## QuickStart\n\nRESPX is a simple, _yet powerful_, utility for mocking out the\n[HTTPX](https://www.python-httpx.org/), _and\n[HTTP Core](https://www.encode.io/httpcore/)_, libraries.\n\nStart by [patching](https://lundberg.github.io/respx/guide/#mock-httpx) `HTTPX`, using\n`respx.mock`, then add request\n[routes](https://lundberg.github.io/respx/guide/#routing-requests) to mock\n[responses](https://lundberg.github.io/respx/guide/#mocking-responses).\n\n```python\nimport httpx\nimport respx\n\nfrom httpx import Response\n\n\n@respx.mock\ndef test_example():\n my_route = respx.get(\"https://example.org/\").mock(return_value=Response(204))\n response = httpx.get(\"https://example.org/\")\n assert my_route.called\n assert response.status_code == 204\n```\n\n> Read the [User Guide](https://lundberg.github.io/respx/guide/) for a complete\n> walk-through.\n\n### pytest + httpx\n\nFor a neater `pytest` experience, RESPX includes a `respx_mock` _fixture_ for easy\n`HTTPX` mocking, along with an optional `respx` _marker_ to fine-tune the mock\n[settings](https://lundberg.github.io/respx/api/#configuration).\n\n```python\nimport httpx\nimport pytest\n\n\ndef test_default(respx_mock):\n respx_mock.get(\"https://foo.bar/\").mock(return_value=httpx.Response(204))\n response = httpx.get(\"https://foo.bar/\")\n assert response.status_code == 204\n\n\n@pytest.mark.respx(base_url=\"https://foo.bar\")\ndef test_with_marker(respx_mock):\n respx_mock.get(\"/baz/\").mock(return_value=httpx.Response(204))\n response = httpx.get(\"https://foo.bar/baz/\")\n assert response.status_code == 204\n```\n\n## Installation\n\nInstall with pip:\n\n```console\n$ pip install respx\n```\n\nRequires Python 3.7+ and HTTPX 0.21+. See\n[Changelog](https://github.com/lundberg/respx/blob/master/CHANGELOG.md) for older HTTPX\ncompatibility.\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "A utility for mocking out the Python HTTPX and HTTP Core libraries.",
"version": "0.21.1",
"project_urls": {
"Changelog": "https://github.com/lundberg/respx/blob/master/CHANGELOG.md",
"GitHub": "https://github.com/lundberg/respx",
"Homepage": "https://lundberg.github.io/respx/",
"Issues": "https://github.com/lundberg/respx/issues"
},
"split_keywords": [
"httpx",
" httpcore",
" mock",
" responses",
" requests",
" async",
" http"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a55c428523509b26c243c1e93aa2ae385def597ef1fbdbbd47978430ba19037d",
"md5": "6f0313019b23d3e5d98690ab35e33726",
"sha256": "05f45de23f0c785862a2c92a3e173916e8ca88e4caad715dd5f68584d6053c20"
},
"downloads": -1,
"filename": "respx-0.21.1-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "6f0313019b23d3e5d98690ab35e33726",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.7",
"size": 25130,
"upload_time": "2024-03-27T20:41:55",
"upload_time_iso_8601": "2024-03-27T20:41:55.709468Z",
"url": "https://files.pythonhosted.org/packages/a5/5c/428523509b26c243c1e93aa2ae385def597ef1fbdbbd47978430ba19037d/respx-0.21.1-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "fd72979e475ade69bcbb18288604aacbdc77b44b3bd1133e2c16660282a9f4b8",
"md5": "66755852123f39634eee126f18cd4c27",
"sha256": "0bd7fe21bfaa52106caa1223ce61224cf30786985f17c63c5d71eff0307ee8af"
},
"downloads": -1,
"filename": "respx-0.21.1.tar.gz",
"has_sig": false,
"md5_digest": "66755852123f39634eee126f18cd4c27",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 28306,
"upload_time": "2024-03-27T20:41:59",
"upload_time_iso_8601": "2024-03-27T20:41:59.929088Z",
"url": "https://files.pythonhosted.org/packages/fd/72/979e475ade69bcbb18288604aacbdc77b44b3bd1133e2c16660282a9f4b8/respx-0.21.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-27 20:41:59",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lundberg",
"github_project": "respx",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "respx"
}