fastapi-lifespan-manager
FastAPI Lifespan Manager
Decision gist · record as of 2026-08-14
Yes, if you have a FastAPI application with multiple resources that need coordinated startup and shutdown. The package is actively maintained, has no known vulnerabilities, and solves a real organizational problem—keeping lifespan logic modular and readable. The low install friction and permissive license make adoption straightforward. Not necessary for simple applications with only one or two resources.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Low friction: pure Python wheel with only fastapi as a runtime dependency.
- Repository is active with recent commits and no archived status, though the package is relatively young (first release April 2023).
License · maintenance · safety
MIT (permissive) — MIT license is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
last release 2024-02-20 (906 days) · last repo commit 2026-08-14 · 42 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 100,501 downloads/mo, #12,984 on PyPI
Alternatives
Verify before relying
pip install fastapi-lifespan-manager
from fastapi import FastAPI
from fastapi_lifespan_manager import LifespanManager
manager = LifespanManager()
@manager.add
async def setup_resource(app: FastAPI):
# Initialize resource
yield {"resource": resource}
# Cleanup
app = FastAPI(lifespan=manager)- Whether the package handles exception cases during lifespan setup or teardown gracefully
- Performance characteristics when managing many concurrent lifespan handlers
- Compatibility with FastAPI's native lifespan parameter in versions after 0.93
What it is and what it does
fastapi-lifespan-manager wraps FastAPI's lifespan context manager to allow you to register multiple startup and shutdown handlers without nesting or manually combining them. Instead of writing a single monolithic lifespan context manager, you decorate individual async generator functions with @manager.add, each yielding a dictionary of state to attach to the app. The manager collects these handlers and runs them sequentially during application startup and shutdown.
This is particularly useful for applications that need to initialize multiple external resources—databases, caches, message queues, connection pools—where each resource has its own setup and teardown logic. Rather than manually coordinating all of these in one place, you can define each resource's lifecycle independently and let the manager orchestrate them. The package depends only on fastapi and supports Python 3.8 through 3.12.
Use it for
- Initialize multiple databases and caches on startup, ensuring each is properly closed when the app shuts down.
- Manage background task workers or thread pools that need to be started at app launch and stopped cleanly.
- Coordinate setup of external service clients (Redis, Elasticsearch, etc.) with their respective cleanup routines.
- Separate resource initialization logic into modular, reusable handlers rather than one large lifespan function.
- Build plugin or extension systems where each module registers its own startup and shutdown behavior.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, if you have a FastAPI application with multiple resources that need coordinated startup and shutdown.
The package is actively maintained, has no known vulnerabilities, and solves a real organizational problem—keeping lifespan logic modular and readable. The low install friction and permissive license make adoption straightforward. Not necessary for simple applications with only one or two resources.
Install
fastapi-lifespan-manager on PyPI
Before you install
Low friction: pure Python wheel with only fastapi as a runtime dependency. Repository is active with recent commits and no archived status, though the package is relatively young (first release April 2023).
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install fastapi-lifespan-manager
from fastapi import FastAPI
from fastapi_lifespan_manager import LifespanManager
manager = LifespanManager()
@manager.add
async def setup_resource(app: FastAPI):
# Initialize resource
yield {"resource": resource}
# Cleanup
app = FastAPI(lifespan=manager)
Verify before relying
- Whether the package handles exception cases during lifespan setup or teardown gracefully
- Performance characteristics when managing many concurrent lifespan handlers
- Compatibility with FastAPI's native lifespan parameter in versions after 0.93
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.8,<4.0 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagefastapi |
| Maintenance | Actively maintained 906 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 100,501 / month, #12,984 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | License :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9 |
Evidence: fastapi_lifespan_manager-0.1.4-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “fastapi lifespan management”
- fastapi-lifespan-managerProvides a lifespan manager for FastAPI that allows multiple startup…
- fastapi-utilitiesProvides reusable utilities for FastAPI applications including…
- asgi-lifespanProgrammatically trigger ASGI application startup and shutdown events…
Give your agent the search over MCP, or paste the wish link into any chat.
More Application Frameworks packages
FastAPI is a Python web framework for building REST APIs using type hints, with automatic request validation, serialization, and interactive API documentation.
Provides a way to document function parameters, class attributes, return types, and variables inline using Python's `Annotated` type hint syntax instead of traditional docstrings.
Textual is a Python framework for building cross-platform user interfaces that run in the terminal or web browser using a modern, component-based API.
Install it if you're developing CLI tools, dashboards, or interactive terminal applications.
Typer builds command-line applications from Python functions using type hints, automatically generating help text, argument parsing, and shell completion.
Install it if you are building CLIs in Python.
Build and connect to Model Context Protocol servers that expose tools, resources, and prompts to LLM applications over stdio, HTTP, or SSE transports.
Install it if you need to build or connect to servers.
Werkzeug is a WSGI utility library providing request/response objects, URL routing, an interactive debugger, HTTP utilities, and a development server for building web applications.
See also asgi-lifespan · fastapi-cache2 · starsessions · fastapi-utilities · fastapi-cli · fastapi-injectable · FastAPI-SQLAlchemy · taskiq-fastapi · nc-py-api · growthbook