skillfed

httmock

A mocking library for requests.

httmock v1.4.0 2.0M downloads/30d#3,393 on PyPI472
Permissive license Apache-2.0 DORMANT released

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 httmock

uv

uv add httmock

poetry

poetry add httmock

Installing 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

Intended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseOperating System :: OS IndependentProgramming Language :: Python :: 2Programming Language :: Python :: 3Topic :: Software Development :: Testing

Tags

mock requests libraryhttp mocking for testsfake api responsesrequests mock decoratortest without network callsintercept http requestsrequests library testing
testingmockingrequests

More Testing packages