Adapter to running ASGI applications on aiohttp
Project Links
Meta
Author: Dmitry Orlov
Requires Python: >=3.9,<4.0
Classifiers
Development Status
- 4 - Beta
Intended Audience
- Developers
License
- OSI Approved :: Apache Software License
Natural Language
- English
Operating System
- MacOS
- Microsoft
- POSIX
Programming Language
- Python
- Python :: 3
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12
- Python :: 3.13
- Python :: 3.7
- Python :: 3.8
- Python :: Implementation :: CPython
- Python :: Implementation :: PyPy
Topic
- Internet
- Software Development
- Software Development :: Libraries
aiohttp-asgi
This module provides a way to use any ASGI compatible frameworks and aiohttp together.
Example
from aiohttp import web
from fastapi import FastAPI
from starlette.requests import Request as ASGIRequest
from aiohttp_asgi import ASGIResource
asgi_app = FastAPI()
@asgi_app.get("/asgi")
async def root(request: ASGIRequest):
return {
"message": "Hello World",
"root_path": request.scope.get("root_path")
}
aiohttp_app = web.Application()
# Create ASGIResource which handle
# any request startswith "/asgi"
asgi_resource = ASGIResource(asgi_app, root_path="/asgi")
# Register resource
aiohttp_app.router.register_resource(asgi_resource)
# Mount startup and shutdown events from aiohttp to ASGI app
asgi_resource.lifespan_mount(aiohttp_app)
# Start the application
web.run_app(aiohttp_app)
Installation
pip install aiohttp-asgi
ASGI HTTP server
Command line tool for starting aiohttp web server with ASGI app.
Example
Create the test_app.py
from starlette.applications import Starlette
from starlette.responses import JSONResponse
from starlette.routing import Route
async def homepage(request):
return JSONResponse({'hello': 'world'})
routes = [
Route("/", endpoint=homepage)
]
application = Starlette(debug=True, routes=routes)
and run the test_app.py with aiohttp-asgi
aiohttp-asgi \
--address "[::1]" \
--port 8080 \
test_app:application
alternatively using python -m
python -m aiohttp_asgi \
--address "[::1]" \
--port 8080 \
test_app:application
0.6.1
Jun 10, 2025
0.6.0
Jun 10, 2025
0.5.2
Mar 20, 2023
0.5.0
Dec 25, 2022
0.4.3
Dec 19, 2022
0.4.2
Dec 19, 2022
0.4.1
Dec 19, 2022
0.4.0
Oct 26, 2021
0.3.2
Sep 29, 2021
0.3.1
Apr 05, 2021
0.3.0
Jan 20, 2021
0.2.0
Nov 09, 2020
0.1.0
Nov 05, 2020
0.0.1
Aug 11, 2020
Wheel compatibility matrix
Files in release
Extras:
None
Dependencies:
aiohttp
(<4,>=3)