asgi-lifespan-middleware
ASGI middlewate to support ASGI lifespans using a simple async context manager interface.
This middleware accepts an ASGI application to wrap and an async context manager lifespan. It will run both the lifespan it was handed directly and that of the ASGI app (if the wrapped ASGI app supports lifespans).
Example (Starlette)
Starlette apps already support lifespans so we'll just be using the TestClient against a plain ASGI app that does nothing.
from contextlib import asynccontextmanager
from typing import AsyncIterator
from starlette.testclient import TestClient
from starlette.types import ASGIApp, Scope, Send, Receive
from asgi_lifespan_middleware import LifespanMiddleware
@asynccontextmanager
async def lifespan(
# you'll get the wrapped app injected
app: ASGIApp,
) -> AsyncIterator[None]:
print("setup")
yield
print("teardown")
async def app(scope: Scope, receive: Receive, send: Send) -> None:
... # do nothing
wrapped_app = LifespanMiddleware(
app,
lifespan=lifespan,
)
with TestClient(wrapped_app):
pass
Release files for asgi-lifespan-middleware 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| asgi_lifespan_middleware-0.1.3.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| asgi_lifespan_middleware-0.1.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.7 kB
Release files / asgi_lifespan_middleware-0.1.3.tar.gz
| Download URL | asgi_lifespan_middleware-0.1.3.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
88adb5932e90e47f8a1ac075ce974c39e39def90b99edb43801732102ae5d132
|
|
BLAKE2b-256 checksum How to use checksums |
af14e413ef0ed1878a6c84296dd9103653eb9a838a6196acb98d21ec52b059ce
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.3 Darwin/21.6.0
|
Release files / asgi_lifespan_middleware-0.1.3-py3-none-any.whl
| Download URL | asgi_lifespan_middleware-0.1.3-py3-none-any.whl |
|---|---|
| Size | 5.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c36734c0bc33f416621ed050c092391b89f0c312b462976d7536e2be941d780d
|
|
BLAKE2b-256 checksum How to use checksums |
650c8776c4453a002bf9476c5aafac520c14c5046288190ff34b58f68857138c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.3 Darwin/21.6.0
|