aiohttp-middlewares
Collection of useful middlewares for aiohttp applications.
What it is and what it does
aiohttp-middlewares is a curated collection of middleware functions designed to fill gaps in aiohttp.web's built-in middleware offerings. It addresses common web-development patterns—CORS header injection, centralized error handling, request shielding—that developers would otherwise implement themselves. The package works as a drop-in set of middleware factories that you pass to aiohttp's Application constructor.
The package depends on aiohttp, async-timeout, and yarl, all standard async-web components. It is actively maintained, supports Python 3.8 through 3.12, and carries no known security vulnerabilities. The BSD-3-Clause license permits use in any project type.
Use it for:
- Enable CORS headers for cross-origin requests in a single middleware registration.
- Centralize error handling and HTTP exception responses across all routes.
- Shield view handlers from cancellation during request processing.
- Add request/response logging or timing middleware to an aiohttp application.
- Implement common security headers or request validation patterns without custom code.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a collection of ready-to-use middlewares for aiohttp.web applications, covering common needs like CORS headers, error handling, and request shielding.
Yes. Active maintenance, no vulnerabilities, low install friction, and a permissive license make this a safe choice. Install it if you are building an aiohttp.web application and want to avoid writing standard middleware boilerplate for CORS, error handling, or similar cross-cutting concerns.
Install
aiohttp-middlewares on PyPI
pip
pip install aiohttp-middlewaresuv
uv add aiohttp-middlewarespoetry
poetry add aiohttp-middlewaresInstalling aiohttp-middlewares
Before you install
Low install friction with a pure-Python wheel. Active maintenance with a recent commit on 2026-03-30 and stable production status.
License in practice
BSD-3-Clause is permissive; you can use this in commercial and proprietary projects with minimal restrictions, provided you include the license text.
Quickstart
pip install aiohttp-middlewares
from aiohttp import web
from aiohttp_middlewares import cors_middleware, error_middleware
app = web.Application(
middlewares=(
cors_middleware(origins=("http://localhost:8081",)),
error_middleware(),
)
)
Requires aiohttp 3.8.1 or later and Python 3.8+.
Verify before relying
- Whether all advertised middlewares are documented and which ones are most commonly used in production.
- Performance characteristics when stacking multiple middlewares on high-traffic applications.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (<4.0,>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 3 — aiohttp, async-timeout, yarl |
| Maintenance | actively maintained — 730 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 198,526/month — #9,727 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: aiohttp_middlewares-2.4.0-py3-none-any.whl
Keywords: aiohttp, aiohttp-server, middlewares, aiohttp-middlewares
Tags
More WWW/HTTP packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
h11h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
httpxHTTPX is a fully featured HTTP client library…
permissive · top 100 on PyPI
httpcoreA minimal low-level HTTP client library that…
permissive · top 100 on PyPI
aiohttpaiohttp is an async HTTP client and server…
permissive · top 100 on PyPI
aiohttp-basicauthProvides HTTP basic authentication middleware…
permissive · top 15,000 on PyPI
aiohttp-corsAdds Cross-Origin Resource Sharing (CORS)…
permissive · top 5,000 on PyPI
aiohttp-sessionProvides session management for aiohttp.web…
permissive · top 15,000 on PyPI
aiohttp-wsgiRuns WSGI applications like Django and Flask on…
permissive · top 15,000 on PyPI
django-cors-headersAdds Cross-Origin Resource Sharing (CORS)…
permissive · top 1,000 on PyPI
flask-corsFlask-CORS handles Cross-Origin Resource…
permissive · top 1,000 on PyPI
aiohttp-jinja2Integrates Jinja2 template rendering into…
permissive · top 5,000 on PyPI
quart-corsQuart-CORS adds Cross-Origin Resource Sharing…
permissive · top 15,000 on PyPI
aiointerceptIntercepts aiohttp client requests by routing…
permissive · top 15,000 on PyPI
aiohttp-swaggerGenerates Swagger API documentation and…
permissive · top 15,000 on PyPI