httmock
A mocking library for requests.
What it is and what it does
httmock is a mocking library that intercepts HTTP requests made by the requests library, letting you replace real API calls with predefined mock responses during testing. It works by decorating handler functions with urlmatch (to conditionally mock specific URLs) or all_requests (to mock all requests), then wrapping your test code in an HTTMock context manager. The library lets you return simple dictionaries or use the response() method to construct full HTTP responses with status codes, headers, and cookies.
The package is straightforward and has low install friction—it depends only on requests. However, it has been dormant since late 2020, with no active maintenance or updates. It remains functional for basic mocking tasks, but you should verify compatibility with your current Python and requests versions before relying on it in new projects.
Use it for:
- Unit test code that calls third-party REST APIs without making real network requests.
- Mock specific API endpoints conditionally using URL patterns to test error handling and edge cases.
- Simulate API rate-limit responses or error codes to verify your application's retry logic.
- Test libraries or frameworks that use requests internally by intercepting their HTTP calls.
- Verify cookie handling and response headers in requests-based code without a live server.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Intercepts and mocks HTTP requests made by the requests library, allowing you to test code that calls external APIs without making real network calls.
Yes, if you need basic HTTP mocking for requests-based code and your project is on stable Python and requests versions. The dormant maintenance status means no new features or bug fixes, so verify compatibility first. For new projects or active development, consider whether a more actively maintained alternative better suits your needs.
Install
httmock on PyPI
pip
pip install httmockuv
uv add httmockpoetry
poetry add httmockInstalling httmock
Before you install
Low friction install with a single lightweight dependency on requests. However, the package is dormant—last release was 2020-10-28, over five years ago, and no commits since 2023-09-29. It still works for its stated purpose but receives no active maintenance.
License in practice
Licensed under Apache-2.0 (permissive), which allows commercial and private use with minimal restrictions—suitable for most projects.
Quickstart
pip install httmock
from httmock import urlmatch, HTTMock
import requests
@urlmatch(netloc=r'example\.com$')
def mock_handler(url, request):
return {'status_code': 200, 'content': 'mocked response'}
with HTTMock(mock_handler):
r = requests.get('http://example.com/')
print(r.content)
Verify before relying
- Whether the package works reliably with modern versions of requests and Python 3.10+, given the dormant maintenance status.
- Whether urlmatch regex patterns and response handling remain compatible with current requests internals.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — requests |
| Maintenance | dormant — 2,116 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,973,040/month — #3,393 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: httmock-1.4.0-py3-none-any.whl
Keywords: requests, testing, mock
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
mocketMocket is a socket mocking framework that…
permissive · top 15,000 on PyPI
pytest-responsesAutomatically mocks HTTP requests across your…
permissive · top 15,000 on PyPI
smithy-httpProvides HTTP primitives, interfaces, and…
permissive · top 15,000 on PyPI
wiremockPython client library for interacting with…
permissive · top 15,000 on PyPI
pookpook intercepts and mocks HTTP traffic for…
permissive · top 15,000 on PyPI
aiointerceptIntercepts aiohttp client requests by routing…
permissive · top 15,000 on PyPI
requests-mockIntercepts and mocks HTTP requests made through…
permissive · top 1,000 on PyPI
responsesMocks HTTP requests made by the requests…
permissive · top 1,000 on PyPI
flexmockflexmock creates mock, stub, spy, and fake…
permissive · top 15,000 on PyPI
http-exceptionsProvides a set of raisable exception classes…
permissive · top 15,000 on PyPI