--- id: asgi-lifespan version: "2.1.0" license: MIT license_treatment: permissive maintenance: aging --- # asgi-lifespan — Programmatic startup/shutdown of ASGI apps. License: permissive · Maintenance: aging · Downloads: 10.5M/mo ## What it is and what it does asgi-lifespan provides a LifespanManager context manager that sends ASGI lifespan events (startup and shutdown) to an ASGI application without requiring an HTTP server to be running. This is primarily useful for testing and mocking ASGI applications—you can combine it with an ASGI-capable HTTP client to send test requests into an app that has been properly initialized through its lifespan protocol. The package automatically detects whether you are running under asyncio or trio and handles the async context accordingly. It supports configurable startup and shutdown timeouts, exposes lifespan state for use in request handling, and raises clear exceptions if the application does not support the lifespan protocol or if timeouts occur. The single runtime dependency is sniffio, keeping installation friction minimal. Use it for: - Write tests for ASGI applications that need lifespan setup and teardown without spinning up a test server. - Mock ASGI applications in unit tests by triggering their startup and shutdown handlers programmatically. - Access and verify lifespan state in an ASGI app during testing via the manager's state-aware app reference. - Test ASGI middleware and lifespan event handlers in isolation without deploying to a running server. - Verify that an ASGI app's startup and shutdown logic executes correctly before integration testing. ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Programmatically trigger ASGI application startup and shutdown events without running a server, enabling testing and mocking of ASGI apps in isolation. Yes, if you test ASGI applications. It is a small, stable, permissive-licensed tool with low install friction and no known vulnerabilities. The long gap since the last release (2023-03-28) is a minor concern for new Python versions, but the repository remains active and the package is marked production/stable. Verify compatibility with your Python version before relying on it for new projects. ## Install pip install asgi-lifespan uv add asgi-lifespan poetry add asgi-lifespan ## Installing asgi-lifespan Before you install: Low friction: single pure-Python dependency (sniffio). Package is in production/stable status but aging—last release was 2023-03-28, over two years old. Repository remains active with recent commits (2026-02-11) and no archived status, though the long gap between releases may signal maintenance is minimal rather than active. License in practice: MIT license is permissive with no restrictions on use, modification, or distribution in proprietary or open-source projects. Quickstart: from asgi_lifespan import LifespanManager async def main(): async with LifespanManager(app) as manager: print("App started") import asyncio asyncio.run(main()) Requires an async runtime (asyncio or trio); the package auto-detects which one is in use via sniffio. Verify before relying: - Whether the package works with ASGI applications beyond those mentioned in the description. - Current compatibility with Python 3.12+ given the last release was 2023-03-28 and classifiers list only up to 3.11. ## Package facts - License: MIT (permissive) - Python support: supports_current - Install friction: low - Maintenance: aging - Downloads: 10.5M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags asgi lifespan testing, asgi app startup shutdown, mock asgi application, asgi lifespan events, test asgi without server, asgi context manager, lifespan protocol handler, asgi-testing, async-context-manager [View on SkillFed](https://skillfed.io/packages/asgi-lifespan) · [View on PyPI](https://pypi.org/project/asgi-lifespan/)