requests-mock
Mock out responses from the requests package
Install
requests-mock on PyPI
pip
pip install requests-mockuv
uv add requests-mockpoetry
poetry add requests-mockPackage facts
| License | Apache-2 (permissive) |
| Python support | supports the current Python release (>=3.5) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — requests |
| Maintenance | dormant — 867 days since the last release |
| Last repo commit | |
| First released | |
| Popularity | one of the top 1,000 most-downloaded packages on PyPI (30-day window, as of 2026-08-13) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-13) |
Evidence: requests_mock-1.12.1-py2.py3-none-any.whl
About requests-mock
from the package's own PyPI description — quoted content, verbatim
=============================== requests-mock ===============================
.. image:: https://badge.fury.io/py/requests-mock.png :target: https://pypi.org/project/requests-mock/
Intro
requests-mock provides a building block to stub out the HTTP requests portions of your testing code.
You should checkout the docs for more information.
The Basics
Everything in requests_ eventually goes through an adapter to do the transport work.
requests-mock creates a custom adapter that allows you to predefine responses when certain URIs are called.
There are then a number of methods provided to get the adapter used.
A simple example:
.. code:: python
>>> import requests
>>> import requests_mock
>>> session = requests.Session()
>>> adapter = requests_mock.Adapter()
>>> session.mount('mock://', adapter)
>>> adapter.register_uri('GET', 'mock://test.com', text='data')
>>> resp = session.get('mock://test.com')
>>> resp.status_code, resp.text
(200, 'data')
Obviously having all URLs be mock:// prefixed isn't going to be useful,
so you can use requests_mock.Mocker to get the adapter into place.
As a context...
Read as markdown · JSON record · Source repository · Homepage
AI interpretation — verify before relying
AI-generated interpretation of the package facts above; every digit, version, license, or vulnerability id it cites is grounded in the facts already shown on this page
requests-mock stubs HTTP responses from the requests library during testing by intercepting calls through a custom adapter, letting you predefine mock responses for specific URIs.
Low friction: pure Python wheel with a single runtime dependency (requests). Maintenance is dormant—last release was 867 days ago—but the repository remains active with recent commits (2024-07-15) and no archived status, suggesting stability rather than abandonment.
Licensed under Apache License 2.0 (permissive), allowing commercial and private use with minimal restrictions; you must retain license and copyright notices in distributions.
Usage
pip install requests-mock
import requests
import requests_mock
with requests_mock.Mocker() as m:
m.get('http://test.com', text='data')
resp = requests.get('http://test.com')
print(resp.text) # 'data'
Verdict: Stable, low-friction testing utility for mocking requests library calls. Dormant maintenance (867 days since last release) poses minimal risk given its narrow, well-defined scope and zero known vulnerabilities. Suitable for projects that need reliable HTTP mocking without active development pressure.
Needs verification
- Whether dormancy reflects genuine stability or signals future incompatibility with newer requests versions
- Test coverage and integration test suite health relative to supported Python versions (3.8–3.12)
Similar packages
permissive · top 1,000 on PyPI
pytest-mockpermissive · top 1,000 on PyPI
respxpermissive · top 1,000 on PyPI
vcrpypermissive · top 1,000 on PyPI
mockpermissive · top 1,000 on PyPI
requests-filepermissive · top 1,000 on PyPI
pyicebergpermissive · top 1,000 on PyPI
pytest-httpxpermissive · top 1,000 on PyPI
snowplow-trackerpermissive · top 1,000 on PyPI
factory-boypermissive · top 1,000 on PyPI