responses (Python)
Mock library for the Python requests library. responses intercepts requests.get/post/put/delete calls and returns registered mock responses, capturing the outgoing request details. Unlike HTTPretty (socket-level), responses patches requests specifically — providing better request inspection (what URL was called, what headers were sent, how many times). Maintained by Sentry — widely used for testing requests-based agent code.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Local testing library — no network calls when properly configured. ConnectionError for unregistered URLs prevents accidental real API calls.
⚡ Reliability
Best When
Your Python agent code uses the requests library and you need HTTP mocking with request inspection — responses provides the cleanest API for requests-specific testing.
Avoid When
You're using httpx (use respx), aiohttp (use aioresponses), or need to mock multiple HTTP libraries in the same test suite.
Use Cases
- • Mock HTTP API calls in Python agent unit tests using requests — register URL patterns with mock responses and verify calls were made
- • Inspect what HTTP requests agent code makes — responses captures call count, URL, body, headers for assertion in tests
- • Simulate API error conditions for agent resilience tests — register 429, 500, or ConnectionError responses for specific endpoints
- • Test agent retry logic with response sequences — register multiple responses for the same URL that return different values per call
- • Passthrough specific URLs to real servers during testing while mocking others — responses.add_passthrough() for selective interception
Not For
- • Code using httpx or aiohttp — responses only works with requests library; use respx for httpx
- • Tests needing socket-level interception across multiple HTTP libraries — use HTTPretty for multi-library mocking
- • Async tests with aiohttp — use aioresponses for aiohttp-specific mocking
Interface
Authentication
Local testing library — no external auth or network calls during test.
Pricing
Apache 2.0 licensed open source maintained by Sentry.
Agent Metadata
Known Gotchas
- ⚠ responses only intercepts the requests library — code that uses urllib, httpx, or aiohttp will bypass the mock and make real network calls; verify all HTTP clients are requests-based
- ⚠ By default, calling an unregistered URL raises ConnectionError — use responses.passthrough_prefixes or assert_all_requests_are_fired=False to control handling of unexpected requests
- ⚠ responses.calls tracks all intercepted requests — long test sessions accumulate calls; use responses.reset() between tests if using the module-level API instead of decorators
- ⚠ URL matching is exact by default — query parameter order matters unless using match_querystring=False or URL pattern matching with re.compile()
- ⚠ Registering the same URL multiple times creates a response queue — first call uses first response, second call uses second; running out of registered responses raises ConnectionError
- ⚠ responses doesn't support streaming responses — agent code that calls iter_content() or iter_lines() may not behave the same as with real streaming HTTP responses
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for responses (Python).
Scores are editorial opinions as of 2026-03-06.