AIOHTTP Connector for running ASGI applications
Reason this release was yanked:
internal only
Project description
aiohttp-asgi
AIOHTTP Connector for running 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 Python 3.8+ and AIOHTTP 3+.
Installation
$ pdm add aiohttp-asgi-connector
# or
$ python -m pip install --user aiohttp-asgi-connector
Usage
This library replaces the entire connection stack and pool 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())
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.
License
This software is licensed under the BSD 3-Clause License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for aiohttp_asgi_connector-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1e6b721cef3f3483873fa5b466f8dcba3f5d3338fd93d46188df459c47747d8 |
|
MD5 | 105574bbb494a8ffc7699dcb6fa2a492 |
|
BLAKE2b-256 | 334d10d35743ce5bb48174f3d0504e8746224263f61584430a2c3081738b85f3 |
Hashes for aiohttp_asgi_connector-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4970cd1aeb3bca65ab1dfce1cfa31439b3381b7d0243f8da6332d415f37e1bda |
|
MD5 | 7839490438424794fb779e340b201be8 |
|
BLAKE2b-256 | 3dcdca190e6711d3f9b09e54929b120df33a72362b71a41cdbb03387b8a6d800 |