<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.8+ and HTTPX 0.25+. 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.8",
"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/f4/7c/96bd0bc759cf009675ad1ee1f96535edcb11e9666b985717eb8c87192a95/respx-0.22.0.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.8+ and HTTPX 0.25+. 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.22.0",
"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": "8e67afbb0978d5399bc9ea200f1d4489a23c9a1dad4eee6376242b8182389c79",
"md5": "b7d60d7b065ede92aaa595dae8210b06",
"sha256": "631128d4c9aba15e56903fb5f66fb1eff412ce28dd387ca3a81339e52dbd3ad0"
},
"downloads": -1,
"filename": "respx-0.22.0-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "b7d60d7b065ede92aaa595dae8210b06",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.8",
"size": 25127,
"upload_time": "2024-12-19T22:33:57",
"upload_time_iso_8601": "2024-12-19T22:33:57.837969Z",
"url": "https://files.pythonhosted.org/packages/8e/67/afbb0978d5399bc9ea200f1d4489a23c9a1dad4eee6376242b8182389c79/respx-0.22.0-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "f47c96bd0bc759cf009675ad1ee1f96535edcb11e9666b985717eb8c87192a95",
"md5": "65335944c75a981b031bba4fe88376a1",
"sha256": "3c8924caa2a50bd71aefc07aa812f2466ff489f1848c96e954a5362d17095d91"
},
"downloads": -1,
"filename": "respx-0.22.0.tar.gz",
"has_sig": false,
"md5_digest": "65335944c75a981b031bba4fe88376a1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 28439,
"upload_time": "2024-12-19T22:33:59",
"upload_time_iso_8601": "2024-12-19T22:33:59.374532Z",
"url": "https://files.pythonhosted.org/packages/f4/7c/96bd0bc759cf009675ad1ee1f96535edcb11e9666b985717eb8c87192a95/respx-0.22.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-19 22:33: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"
}