What problem does it solve?
This Skill helps developers safely manage the lifecycle of async resources in FastAPI applications by using a lifespan context manager and simple, type-safe dependency injection to ensure resources are initialized on startup and cleaned up on shutdown.
Core Features & Use Cases
- Lifespan-based resource lifecycle management (initialize on startup, cleanup on exit) for resources like HTTP clients and database connections.
- Type-safe dependency injection through getter functions to provide resources to route handlers.
- Shared resources across multiple routes with predictable initialization and teardown, reducing boilerplate and errors.
Quick Start
Create a FastAPI app that uses a lifespan context to initialize resources and exposes getter functions for handlers. For example, define a lifespan that creates an HTTP client and a database service, then use get_http_client and get_db_service in route handlers to access them.