requests-mock
Mock out responses from the requests package
Decision gist · record as of 2026-08-14
Yes. This is a stable, low-friction testing utility for any project using requests. It has no security vulnerabilities, a permissive license, and a single lightweight dependency. The dormant maintenance status is not a concern for a mature, narrowly-scoped library—it does one thing well and requires little ongoing change. Install it if you write tests for code that makes HTTP calls.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low friction: pure Python wheel with a single runtime dependency (requests).
- Maintenance is dormant—last release was 2024-03-29 and last commit 2024-07-15—but the package is marked Production/Stable and has seen no recent changes needed.
License · maintenance · safety
Apache-2 (permissive) — Apache-2 (permissive): you can use this freely in commercial and open-source projects, modify it, and distribute it with minimal restrictions—no copyleft obligation.
last release 2024-03-29 (868 days) · last repo commit 2024-07-15 · 466 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 28,678,227 downloads/mo, #830 on PyPI
Alternatives
Verify before relying
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'What it is and what it does
requests-mock is a testing library that intercepts calls made through the requests library and returns pre-defined mock responses instead of making real HTTP requests. It works by registering a custom adapter with a requests Session, allowing you to stub out specific URIs and their responses. This is useful for unit and integration tests where you want to verify your code's HTTP logic without depending on external services or network availability.
The library supports three main usage patterns: mounting an adapter directly to a Session, using it as a context manager, or using it as a pytest fixture. You register mock responses by specifying a method (GET, POST, etc.), a URI pattern, and the response body or status code. When your code makes a matching request, the mock adapter intercepts it and returns your predefined response.
Use it for
- Unit test code that calls external REST APIs without requiring network access or test credentials.
- Verify error handling by mocking specific HTTP status codes and error responses.
- Test request/response logic in isolation by stubbing out third-party service calls.
- Simulate slow or unreliable network conditions for resilience testing.
- Run tests in CI/CD pipelines without external service dependencies.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
This is a stable, low-friction testing utility for any project using requests. It has no security vulnerabilities, a permissive license, and a single lightweight dependency. The dormant maintenance status is not a concern for a mature, narrowly-scoped library—it does one thing well and requires little ongoing change. Install it if you write tests for code that makes HTTP calls.
Install
requests-mock on PyPI
Before you install
Low friction: pure Python wheel with a single runtime dependency (requests). Maintenance is dormant—last release was 2024-03-29 and last commit 2024-07-15—but the package is marked Production/Stable and has seen no recent changes needed.
License in practice
Apache-2 (permissive): you can use this freely in commercial and open-source projects, modify it, and distribute it with minimal restrictions—no copyleft obligation.
Quickstart
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'
Package facts
| License | Apache-2 permissive |
| Python support | Supports the current Python release >=3.5 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagerequests |
| Maintenance | Dormant 868 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 28,678,227 / month, #830 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Information TechnologyLicense :: OSI Approved :: Apache Software LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyTopic :: Software Development :: Testing |
Evidence: requests_mock-1.12.1-py2.py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “mock http requests in tests”
- requests-mockIntercepts and mocks HTTP requests made through the requests library,…
- httmockIntercepts and mocks HTTP requests made by the requests library,…
- pytest-httpx2A pytest plugin that mocks httpx2 HTTP requests using respx, letting…
Give your agent the search over MCP, or paste the wish link into any chat.
More Testing packages
Pluggy provides a plugin system that lets you define hook specifications and register implementations to be called in sequence, enabling extensible Python applications without tight coupling.
Install it if you're building an extensible application or framework.
pytest is a testing framework that lets you write test functions using plain assert statements and automatically discovers and runs them, with detailed failure reporting.
virtualenv creates isolated Python environments where packages can be installed independently without affecting the system Python or other projects.
Coverage.py measures which lines of Python code are executed during test runs, reporting coverage percentages and identifying untested code paths.
Install it if you want to measure test completeness or enforce coverage thresholds in your project.
pytest-asyncio is a pytest plugin that enables writing and running async test functions using the asyncio library, allowing developers to await code directly within test cases.
Install it if you write tests for any asyncio-based code.
A pytest plugin that generates test reports in Common Test Report Format (CTRF) as JSON, compatible with pytest-xdist and pytest-playwright for distributed and browser-based testing.
Install it if you need CTRF-formatted test output for CI/CD integration or cross-tool reporting.
See also responses · httmock · requests-file · aioresponses · mockito · aiointercept · mock · pretend · pytest-responses · pook