httmock: Mock HTTP Requests for Python Tests

Summary
httmock lets Python tests replace HTTP calls made with requests, so you can exercise API clients without contacting real services. It supports conditional URL matching and configurable mocked responses.
At a glance
- Language
- Python
- License
- NOASSERTION
- Stars
- 472
- Forks
- 56
- Added to OSRepos
- August 3, 2026
- Last analyzed
- October 3, 2026
Use at your own risk
OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of code from these repositories is the user's own responsibility. Always review the repository, source code, dependencies, licenses, and security implications before running or installing anything. OSRepos is not responsible for issues, damages, or losses resulting from third-party repositories.
Overview
httmock is a Python library for intercepting HTTP requests made through requests and supplying mocked responses. It helps developers test API clients and other code that uses requests without depending on live services, network availability, or real API data.
It is suited to tests that need to control which requests are intercepted and what status, headers, cookies, or content they receive. The project README documents support for Python 2.7 and Python 3.4+.
Key Features
- Intercepts requests made with the
requestslibrary. - Matches requests by URL using the
urlmatchdecorator. - Provides an
all_requestsdecorator for handling all requests in a test context. - Allows mocked responses to be returned as dictionaries or created with the
responsehelper. - Supports response status codes, content, headers, and cookies.
- Activates handlers within an
HTTMockcontext manager.
Use Cases
- API client authors can test success and error handling without calling a live API.
- Library maintainers can verify code that uses
requestsinternally with predictable responses. - Test authors can simulate particular hosts while leaving unmatched requests unaffected by conditional matching.
- Developers can check response handling for status codes, headers, JSON content, or cookies.
Project Facts
- Language: Python
- License: NOASSERTION
- Stars: 472
- Forks: 56
- Topics: http, mock, python, requests
- Archived: no
Getting Started
Install with pip install httmock. See the README for usage details.
Alternatives
- HTTPretty: HTTPretty intercepts HTTP traffic at the socket level, while httmock focuses on mocking requests with URL-based matchers.
- responses: responses mocks the requests library with a registry of expected calls and responses, while httmock uses URL-matching handlers to configure responses.
Considerations
httmock is designed for the requests library, so it is not presented as a general-purpose mock for every Python HTTP client. The README lists Python 2.7 and 3.4+ as supported versions; check the project documentation and your environment when using newer Python versions. The input reports the license as NOASSERTION, so verify licensing details before adopting it where that matters.
Found this useful?
Share it with someone who would like httmock.
Comparisons
Source repository
Open the original repository on GitHub.
21 counted GitHub visits
Related repositories
Similar repositories that may be relevant next.

omnigent: Orchestrate AI Coding Agents Across Harnesses
October 5, 2026
Omnigent provides a shared orchestration layer for AI coding agents, with policies, sandboxing, and team collaboration. It suits developers who want to combine agent runtimes and access sessions across devices without tying workflows to one harness.

agentevals: Evaluate AI Agents from OpenTelemetry Traces
October 4, 2026
agentevals scores AI agent behavior from existing OpenTelemetry traces, without rerunning agents or making extra model calls. It suits teams building instrumented agents that need local evaluation, golden-set checks, or CI quality gates.

web-design: Create Consistent Web Pages with a Claude Code Skill
October 3, 2026
web-design is a Claude Code skill that turns product briefs, reference URLs, or screenshots into an editable design specification before generating web code. It is suited to developers and designers who want a repeatable, spec-led workflow for building consistent pages.

oomwoo: Build a DIY Robot Vacuum
October 2, 2026
OOMWOO is a planned, hackable robot vacuum built around Raspberry Pi, ROS2 and 2D LiDAR. It is aimed at makers who want to build and customize a locally controlled vacuum, but its hardware and build instructions are still in development.