HTTPretty

HTTP request interceptor library for Python testing. HTTPretty patches Python's socket library to intercept all HTTP connections — it doesn't require changing how HTTP clients are created. Supports all major Python HTTP libraries (requests, httpx, urllib3, boto3, aiohttp) and allows registering fake responses for specific URLs. Used for unit testing code that makes HTTP requests without mocking individual client instances.

Evaluated Mar 06, 2026 (0d ago) v1.x
Homepage ↗ Repo ↗ Developer Tools python testing http mocking requests unit-testing open-source
⚙ Agent Friendliness
63
/ 100
Can an agent use this?
🔒 Security
88
/ 100
Is it safe for agents?
⚡ Reliability
76
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
78
Error Messages
72
Auth Simplicity
100
Rate Limits
95

🔒 Security

TLS Enforcement
88
Auth Strength
90
Scope Granularity
88
Dep. Hygiene
82
Secret Handling
90

Local testing library — no network calls when properly configured. Socket-level patching prevents accidental real API calls in tests.

⚡ Reliability

Uptime/SLA
80
Version Stability
75
Breaking Changes
72
Error Recovery
75
AF Security Reliability

Best When

You need to mock HTTP requests in Python agent tests across multiple HTTP libraries without modifying client creation code — HTTPretty's socket-level interception works universally.

Avoid When

You're using async HTTP (httpx async, aiohttp) — use respx or aioresponses instead. Or if you need detailed request inspection — use responses library.

Use Cases

  • Mock external HTTP API calls in Python agent unit tests without changing how agent code creates HTTP clients
  • Test agent code that uses multiple HTTP libraries (requests + boto3) in the same test — HTTPretty intercepts at socket level
  • Simulate API error responses (429, 500, timeouts) for agent error handling tests without spinning up mock servers
  • Test agent retry logic by registering sequences of responses for the same URL — first call returns 429, second returns 200
  • Write tests for agent code that reads from web APIs without network access in CI environments

Not For

  • Async tests with httpx or aiohttp — HTTPretty has limited async support; use respx for httpx or aioresponses for aiohttp
  • Tests needing response inspection (what request was sent) — use responses or respx which provide better request capture
  • Applications using raw socket connections — HTTPretty patches socket, but very low-level socket code may bypass it

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

Local testing library — no external auth or network calls during test.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

MIT-licensed open source Python package.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • HTTPretty must be activated before any HTTP call — use @httpretty.activate decorator or httpretty.enable() context manager; registering mocks before activation has no effect
  • allow_net_connect=False must be set to prevent real network calls — without it, unmatched requests hit real servers in tests causing flaky results and unintended side effects
  • HTTPretty has known issues with parallel test execution (pytest-xdist) — socket-level patching is process-global; use separate processes (not threads) for parallel HTTPretty tests
  • Async HTTP clients (httpx async, aiohttp) are not fully supported — HTTPretty intercepts at synchronous socket level; use respx for httpx and aioresponses for aiohttp
  • Response streaming with large bodies may behave differently — HTTPretty buffers responses in memory; streaming agent code may not behave the same as with real streaming responses
  • pytest-httpretty plugin may conflict with direct HTTPretty usage — choose one approach per test suite to avoid double-patching

Full Evaluation Report

Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for HTTPretty.

$99

Scores are editorial opinions as of 2026-03-06.

5208
Packages Evaluated
26151
Need Evaluation
173
Need Re-evaluation
Community Powered