httmock: Mock HTTP Requests for Python Tests

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
View on GitHub

Topics

Click on any tag to explore related repositories

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 requests library.
  • Matches requests by URL using the urlmatch decorator.
  • Provides an all_requests decorator for handling all requests in a test context.
  • Allows mocked responses to be returned as dictionaries or created with the response helper.
  • Supports response status codes, content, headers, and cookies.
  • Activates handlers within an HTTMock context manager.

Use Cases

  • API client authors can test success and error handling without calling a live API.
  • Library maintainers can verify code that uses requests internally 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

View on GitHub

Related repositories

Similar repositories that may be relevant next.

OS
OSRepos

Analysis and discovery of open source repositories. Find interesting projects and follow their updates.

Monitor your website with YourWebsiteScore

OSRepos shares public repositories for knowledge and discovery only. Any installation, execution, configuration, or use of third-party repository code is at your own risk. Always review source code, dependencies, licenses, and security implications before running anything.

© 2025 OSRepos. Built with Nuxt 3 and lots of ❤️