Metadata-Version: 2.1
Name: asgi-lifespan-middleware
Version: 0.1.3
Summary: Middleware to handle ASGI lifespans
Home-page: https://github.com/adriangb/asgi-lifespan-middleware
License: MIT
Keywords: web-framework,http,asgi
Author: Adrian Garcia Badaracco
Author-email: adrian@adriangb.com
Requires-Python: >=3.7,<4
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Web Environment
Classifier: Framework :: AsyncIO
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Topic :: Internet
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Project-URL: Documentation, https://github.com/adriangb/asgi-lifespan-middleware
Project-URL: Repository, https://github.com/adriangb/asgi-lifespan-middleware
Description-Content-Type: text/markdown

# 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.

```python
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
```

