aiohttp-asgi-connector
An AIOHTTP ClientSession connector for interacting with ASGI applications.
This library intends to increase the parity between AIOHTTP and HTTPX, specifically with HTTPX's AsyncClient. It is primarily intended to be used in test suite scenarios, or other situations where one would want to interface with an ASGI application directly instead of through a web server.
Supports AIOHTTP 3.1+ on corresponding compatible Python versions.
Installation
$ pdm add aiohttp-asgi-connector
# or
$ python -m pip install --user aiohttp-asgi-connector
Usage
This library replaces the entire connection stack and underlying HTTP transport. AIOHTTP exposes custom connectors via the connector argument supplied when creating a ClientSession instance.
To use the ASGIApplicationConnector:
import asyncio
from typing import Annotated # or from typing_extensions
from aiohttp_asgi_connector import ASGIApplicationConnector
from aiohttp import ClientSession
from fastapi import FastAPI, Body
app = FastAPI()
@app.post("/ping")
async def pong(message: Annotated[str, Body(embed=True)]):
return {"broadcast": f"Application says '{message}'!"}
async def main():
connector = ASGIApplicationConnector(app)
async with ClientSession(
base_url="http://localhost", connector=connector
) as session:
async with session.post("/ping", json={"message": "hello"}) as resp:
print(await resp.json())
# ==> {'broadcast': "Application says 'hello'!"}
asyncio.run(main())
By default, exceptions raised within the ASGI application that are not swallowed by middleware are propagated. This has the side-effect of buffering all known-length responses before sending them to the client, including streaming responses with an explicit Content-Length header. To opt-out, and receive HTTP error responses where
where sen, pass propagate_exceptions=False to ASGIApplicationConnector; this in turn means responses will be streamed as expected.
This connector transmits the request to the ASGI application exactly as it is serialized by AIOHTTP. If upload chunking or compression are enabled for your ClientSession requests, your ASGI application will need to be able to handle de-chunking and de-compressing; FastAPI / Starlette do not do this by default. Support to enable connector-side dechunking and decompressing may come as a future feature if a need is demonstrated for it (file an Issue).
This library does not handle ASGI lifespan events. If you want to run those events, use this library in conjunction with something like asgi-lifespan:
from asgi_lifespan import LifespanManager
async with LifespanManager(app) as manager:
connector = ASGIApplicationConnector(manager.app)
async with ClientSession(
base_url="http://localhost", connector=connector
) as session:
...
License
This software is licensed under the BSD 3-Clause License.
Metadata
Release files for aiohttp-asgi-connector 1.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiohttp_asgi_connector-1.2.0.tar.gz | 6.3 kB | Without provenance | Details for aiohttp_asgi_connector-1.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aiohttp_asgi_connector-1.2.0-py3-none-any.whl | Python 3 | none | any | Details for aiohttp_asgi_connector-1.2.0-py3-none-any.whl |
Total release size: 13.7 kB
Release files / aiohttp_asgi_connector-1.2.0.tar.gz
| Download URL | aiohttp_asgi_connector-1.2.0.tar.gz |
|---|---|
| Size | 6.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d8b8bbd9b1e27f613dfd6a517e584674c6ad01f475f5b00144c1cd50f35d2932
|
|
BLAKE2b-256 checksum How to use checksums |
1c03ceef67003cc21c5d418776272fef363e58cb5ac21af26c4e7b1abb8ca152
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / aiohttp_asgi_connector-1.2.0-py3-none-any.whl
| Download URL | aiohttp_asgi_connector-1.2.0-py3-none-any.whl |
|---|---|
| Size | 7.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c831cf9e14b88d610656a1dd39a2bbe6ae8fa5777600bb27b19b5fae7fd68826
|
|
BLAKE2b-256 checksum How to use checksums |
1895eca864a005841ce39cea1ed789f23f32909c72f1bf0a277bf55510bddae6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.18 {"installer":{"name":"uv","version":"0.12.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for aiohttp-asgi-connector 1.2.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.