HTTPretty vs httmock
Python HTTP mocking libraries compared
HTTPretty and httmock both help Python tests use mocked HTTP responses instead of relying on live services. HTTPretty intercepts traffic at the socket level, while httmock targets requests made through the `requests` library.

HTTPretty: Mock HTTP Requests in Python Tests
HTTPretty intercepts Python HTTP traffic at the socket level and returns registered fake responses. It helps developers test API integrations without relying on live services, and can capture requests for assertions or playback.

httmock: Mock HTTP Requests for Python Tests
httmock is a Python library built on requests for mocking HTTP interactions in tests. It lets you provide conditional or catch-all mocked responses when testing code that calls APIs through requests.
| HTTPretty | httmock | |
|---|---|---|
| Language | Python | Python |
| License | MIT | — |
| Stars | 2.1k | 471 |
| Forks | 285 | 57 |
| Last analyzed | Oct 3, 2026 | Oct 19, 2026 |
Key differences
- HTTPretty intercepts Python HTTP traffic at the socket level; httmock intercepts calls made through `requests`.
- HTTPretty registers fakes by HTTP method and URL and can return multiple responses for repeated requests; httmock offers URL matching with `urlmatch` and handlers for all requests in a test context.
- HTTPretty can capture requests for inspecting bodies and counts; httmock provides configurable response status codes, content, headers, and cookies.
- HTTPretty lists Python 3.6 through 3.9 as supported; httmock lists Python 2.7 and Python 3.4+.
- HTTPretty reports an MIT license, 2.1k stars, and 285 forks; httmock reports `NOASSERTION`, 472 stars, and 56 forks.
Choose HTTPretty if you…
- need socket-level interception rather than interception limited to `requests`.
- want to inspect captured request bodies or counts, or test successive responses to the same URL.
- need the reported MIT license.
Choose httmock if you…
- use the `requests` library and want handlers scoped with a context manager.
- want URL-based matching or response controls for status codes, headers, cookies, and content.
- need the documented Python 2.7 support, or Python 3.4+ support.
Compare the numbers side by side, or add more projects
This comparison is generated with AI from the OSRepos analyses of both projects. Always check each project's repository and documentation before choosing.