Skip to main content

aiohttp-asgi

PyPI - License Wheel PyPI PyPI Coverage Status tests

This module provides a way to use any ASGI compatible frameworks and aiohttp together.

Documentation: https://mosquito.github.io/aiohttp-asgi/. The sources are in docs/, build the HTML locally with make -C docs html.

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

The faster event loops are optional extras:

pip install "aiohttp-asgi[uvloop]"
pip install "aiohttp-asgi[rloop]"

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

Multiple worker processes

The -w/--workers option starts more than one worker process. The parent process binds the socket, then forklib forks the workers, so all workers accept connections from one shared socket. The parent process does not serve requests, it supervises the workers. Zero starts one worker for each CPU.

aiohttp-asgi --workers 4 test_app:application

The package requires forklib on Linux, therefore the option works there without an additional step. On other POSIX systems install forklib with pip install forklib. The CLI shows the option only when forklib is installed, so the option is not available on Windows, which has no fork.

Each worker imports the ASGI application after the fork, because an application can start threads or event loops on import, and the fork does not copy them correctly.

Event loop

Choose an event loop with --event-loop=stdlib, --event-loop=uvloop or --event-loop=rloop. The CLI only offers optional loops that are installed; stdlib is always available. The default preference order is rloop, then uvloop, then stdlib. Each worker imports and creates its event loop after the fork.

pip install "aiohttp-asgi[uvloop]"
aiohttp-asgi --workers 4 --event-loop=uvloop test_app:application

Development

The project uses uv.

uv sync --all-extras
uv run pytest
uv run ruff check
uv run mypy
make -C docs html

Metadata

Release files for aiohttp-asgi 0.7.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiohttp-asgi 0.7.1
File Size Uploaded Provenance
aiohttp_asgi-0.7.1.tar.gz 20.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aiohttp-asgi 0.7.1
File Interpreter ABI Platform
aiohttp_asgi-0.7.1-py3-none-any.whl Python 3 none any Details

Total release size: 36.0 kB

Release files / aiohttp_asgi-0.7.1.tar.gz

Download URL aiohttp_asgi-0.7.1.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
047ba062610f7adfbc6c83a7989c85d8a7fd7b52b554ab87acbd54f0c5bc14fa
BLAKE2b-256 checksum
How to use checksums
216550994f7e8ef1442cb64bfcf5eb1fa34d73bc4e1bd75f692aca26bfe67f97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Release files / aiohttp_asgi-0.7.1-py3-none-any.whl

Download URL aiohttp_asgi-0.7.1-py3-none-any.whl
Size 15.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b26a203b30af56e6027f7446f1a6bac0e1cb0589ebe1c76738245177b8368262
BLAKE2b-256 checksum
How to use checksums
affd2f91c604dea1eae007e5dbff61d74ea78b94b9f4c0fb098dcdc39960a37b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

Security for aiohttp-asgi 0.7.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for aiohttp_asgi-0.7.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 24, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page