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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
aiohttp_asgi-0.6.0.tar.gz
(10.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiohttp_asgi-0.6.0.tar.gz.
File metadata
- Download URL: aiohttp_asgi-0.6.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.1.3 CPython/3.13.2 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
798f685013ba77e3e0a954a28b2f404900b674f1725217c165abcdfaa09a740c
|
|
| MD5 |
13034f8abc5964353bed734bf8a79ae4
|
|
| BLAKE2b-256 |
0498c9ed329328b39f0beb74d207e8aaeb047e44c63028ab82e9ad82666543a3
|
File details
Details for the file aiohttp_asgi-0.6.0-py3-none-any.whl.
File metadata
- Download URL: aiohttp_asgi-0.6.0-py3-none-any.whl
- Upload date:
- Size: 15.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
poetry/2.1.3 CPython/3.13.2 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0af9cd08daff1155ba0e8f5e4580efd7b38707903cf6802c2e5df22df04da159
|
|
| MD5 |
de2e419e0e74278051392f09dbcbad7f
|
|
| BLAKE2b-256 |
2459b9acae33dc024eb7545ed7b795e4f3883bbce23c93f65d27d992eaba59ee
|