Fastapi LifespanManager
fastapi-lifespan-manager is a Python library that provides a lifespan manager for FastAPI applications.
The LifespanManager in fastapi-lifespan-manager allows you to have multiple lifespan in one
application.
This library is particularly useful for managing background tasks, such as starting and stopping a database connection or managing a cache, as well as for performing cleanup tasks, such as closing open file handles or shutting down running processes.
To use fastapi-lifespan-manager, simply install it via pip:
pip install fastapi-lifespan-manager
Usage Example:
from typing import AsyncIterator
from fastapi import FastAPI
from redis.asyncio import Redis
from sqlalchemy.ext.asyncio import create_async_engine
from fastapi_lifespan_manager import LifespanManager, State
manager = LifespanManager()
@manager.add
async def setup_db(app: FastAPI) -> AsyncIterator[State]:
engine = await create_async_engine("postgresql+asyncpg://user:password@localhost/db")
yield {"db": engine}
await engine.dispose()
@manager.add
async def setup_cache(app: FastAPI) -> AsyncIterator[State]:
redis = await Redis.from_url("redis://localhost:6379/0")
yield {"cache": redis}
await redis.close()
await redis.wait_closed()
app = FastAPI(lifespan=manager)
Metadata
Release files for fastapi-lifespan-manager 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| fastapi_lifespan_manager-0.1.4.tar.gz | 4.4 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_lifespan_manager-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.2 kB
Release files / fastapi_lifespan_manager-0.1.4.tar.gz
| Download URL | fastapi_lifespan_manager-0.1.4.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1dc4a776cd4305bf7baf4791f148216c21ab966916216d72b5dc2a27a21d8d02
|
|
BLAKE2b-256 checksum How to use checksums |
061ae559faa77de5d4afa02076de8257bcd492a9ea8c9206f2b3e5e451933349
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1019-azure
|
Release files / fastapi_lifespan_manager-0.1.4-py3-none-any.whl
| Download URL | fastapi_lifespan_manager-0.1.4-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d18e2c01cd91432ed05c7f94a02bb43e9ad68a5a55ccc813005f0b5f79e8bd9
|
|
BLAKE2b-256 checksum How to use checksums |
5682755d5092478a2cdec3528a2b7e4594af1fcc231cabfbbad492be99687191
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.8.18 Linux/6.2.0-1019-azure
|
Security for fastapi-lifespan-manager 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.