fastapi-lifespan-di

Community

Manage FastAPI resource lifecycles with DI.

Authordragonkid
Version1.0.0
Installs0

System Documentation

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.

Dependency Matrix

Required Modules

None required

Components

Standard package

💻 Claude Code Installation

Recommended: Let Claude install automatically. Simply copy and paste the text below to Claude Code.

Please help me install this Skill:
Name: fastapi-lifespan-di
Download link: https://github.com/dragonkid/dotfiles/archive/main.zip#fastapi-lifespan-di

Please download this .zip file, extract it, and install it in the .claude/skills/ directory.
View Source Repository

Agent Skills Search Helper

Install a tiny helper to your Agent, search and equip skill from 223,000+ vetted skills library on demand.