aresponses
Asyncio response mocking. Similar to the responses library used for 'requests'
What it is and what it does
aresponses is a test fixture and mock server for asyncio applications that use aiohttp. It intercepts HTTP and HTTPS requests made by aiohttp.ClientSession and returns predefined responses without touching the network. You define routes using pattern matching (exact strings or regular expressions) on host, path, method, and body, then attach responses—plain text, JSON dicts, custom Response objects, or callable handlers. When your test code makes a request, aresponses matches it to the first registered route, returns the response, and removes that route from the table.
The package is designed for pytest integration and requires explicit assertions at the end of each test to verify that routes were called in order, all routes were used, and no unmatched requests occurred. It supports regex patterns for flexible matching, repeated routes via the repeat parameter, JSON responses as a convenience, custom handler functions, and a passthrough mode to let specific requests reach the real network. Version 3.0.0 updated to use asyncio.get_running_loop() instead of the deprecated event_loop fixture pattern.
Use it for:
- Unit test an async client library or service that calls external APIs without making real HTTP requests.
- Simulate error responses (500, timeouts, malformed JSON) to test error handling in async code.
- Mock multiple external services in a single test by registering different routes for different hosts.
- Verify that your async code calls external APIs in the correct order with the correct parameters.
- Test HTTPS requests by transparently converting them to HTTP mocks without certificate setup.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Mocks external HTTP/HTTPS services for asyncio-based tests by intercepting aiohttp requests and returning predefined responses without making real network calls.
Yes, if you write asyncio tests with aiohttp. It has low install friction, no known vulnerabilities, permissive licensing, and is stable and widely used despite dormant maintenance. The trade-off: the last release was over 945 days ago, so if you need fixes for new Python or aiohttp versions, you may need to fork or wait for a maintainer response. For active projects on current Python (3.7–3.12), it works as-is.
Install
aresponses on PyPI
pip
pip install aresponsesuv
uv add aresponsespoetry
poetry add aresponsesInstalling aresponses
Before you install
Low friction: pure Python wheel with only two runtime dependencies (pytest-asyncio and aiohttp). Maintenance is dormant—last release was 2024-01-12, over 945 days ago, though the repository remains active and the package is widely used (115539 monthly downloads).
License in practice
Licensed under MIT (permissive), so you can use it freely in commercial and private projects with minimal restrictions.
Quickstart
pip install aresponses
import aresponses
import aiohttp
import pytest
@pytest.mark.asyncio
async def test_mock(aresponses):
aresponses.add("example.com", "/api", "GET", response="OK")
async with aiohttp.ClientSession() as session:
async with session.get("http://example.com/api") as resp:
assert await resp.text() == "OK"
aresponses.assert_plan_strictly_followed()
Requires pytest-asyncio to be installed and your test function decorated with @pytest.mark.asyncio; version 3.0.0 uses asyncio.get_running_loop() and may not work with older event loop patterns.
Verify before relying
- Whether the dormant maintenance status (945 days since last release) poses a risk for future Python or aiohttp compatibility.
- Performance characteristics when mocking high-volume or complex request/response patterns.
- Compatibility with pytest-asyncio versions beyond what the fact sheet specifies.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — pytest-asyncio, aiohttp |
| Maintenance | dormant — 945 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 115,539/month — #12,245 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: aresponses-3.0.0-py3-none-any.whl
Keywords: asyncio, testing, responses
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
aioresponsesMocks HTTP requests made by aiohttp's…
permissive · top 5,000 on PyPI
aiosonicAn asyncio HTTP/1.1, HTTP/2, and WebSocket…
permissive · top 15,000 on PyPI
aiointerceptIntercepts aiohttp client requests by routing…
permissive · top 15,000 on PyPI
sanic-testingProvides sync and async test clients for…
permissive · top 15,000 on PyPI
pytest-responsesAutomatically mocks HTTP requests across your…
permissive · top 15,000 on PyPI
urllib3-mockMocks urllib3 HTTP requests in tests by…
permissive · top 15,000 on PyPI
responsesMocks HTTP requests made by the requests…
permissive · top 1,000 on PyPI
pytest-aiohttpPytest plugin that provides fixtures for…
permissive · top 5,000 on PyPI
looptimeLooptime fakes the passage of time in asyncio…
permissive · top 15,000 on PyPI
asyncmockProvides awaitable mock objects for testing…
permissive · top 15,000 on PyPI