fastapi
Skill15 starsChanged 42 days agoMITView on GitHub
Expert FastAPI assistance covering Pydantic models, async endpoints, dependency injection, and OpenAPI generation. Use when developing high-performance Python REST APIs and microservices.
27 other projects use a version of this.
Adopted by
Most recently taken up by
- gurupak/claude-skillstheir own version, first seen Oct 25, 2026
- DongDuong2001/pudo-code-systemtheir own version, first seen Oct 13, 2026
- nimadorostkar/Claude-Skills-collectiontheir own version, first seen Oct 13, 2026
- qyndex/claude-inittheir own version, first seen Oct 13, 2026
- Alteriom/ai-dev-skillstheir own version, first seen Oct 11, 2026
- kid-sid/claude-spellbooktheir own version, first seen Oct 9, 2026
Used with
Projects with it also use plan and frontend-design.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
BlockSkillplan
Draft a TDD, PRD, or lightweight plan in the conversation without committing it.
Also in 3 projects that use this
BlockSkillfrontend-design
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Also in 3 projects that use this
Other versions27 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 27
- kid-sid/claude-spellbook★ 190same name
- youlaitech/youlai-skills★ 63same name
- Bbar0n234/learnflow-ai★ 35same name
- nimadorostkar/Claude-Skills-collection★ 33same name
- harness-studio/harness-studio★ 9same name
- DongDuong2001/pudo-code-system★ 5same name
- jawwad-ali/claude-code-skills★ 4same name
- Spardutti/claude-skills★ 3same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- qyndex/claude-init★ 2same name
17 more not listed
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository350 other files it gives its agents.
- airflowSkill
- catboostSkill
- claudeSkill
- comfyuiSkill
- cursor-aiSkill
- dalleSkill
- daskSkill
- dbtSkill
- deepseekSkill
- fastaiSkill
- geminiSkill
- github-copilotSkill
- huggingfaceSkill
- jaxSkill
- jupyterSkill
- kerasSkill
- langchainSkill
- lightgbmSkill
- llamaindexSkill
- llamaSkill
- matplotlibSkill
- midjourneySkill
- mistralSkill
- mlflowSkill
- nltkSkill
- numpySkill
- ollamaSkill
- openai-gptSkill
- opencvSkill
- pandasSkill
- perplexitySkill
- plotlySkill
- polarsSkill
- pytorchSkill
- raySkill
- scikit-learnSkill
- seabornSkill
- spacySkill
- sparkSkill
- stable-diffusionSkill
- tensorflowSkill
- vaexSkill
- weights-biasesSkill
- whisperSkill
- xgboostSkill
- api-gatewaySkill
- clean-architectureSkill
- cqrsSkill
- domain-driven-designSkill
- event-drivenSkill
- event-sourcingSkill
- graphqlSkill
- grpcSkill
- hexagonalSkill
- microservicesSkill
- modular-monolithSkill
- monolithSkill
- rest-apiSkill
- sagaSkill
- serverlessSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
1 rule. 0 are common, 0 are distinctive, and 1 is very specific to this project.
0
Common
Most of the 25 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 120
Use Depends() with generator context management:
“Common” is measured: kept by at least 6 in 10 of the 25 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
FastAPI
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.8+ based on standard Python type hints. It is one of the fastest Python frameworks available.
When to Use
- High-Performance Python Web APIs: Developing modern async APIs built on Starlette and Pydantic.
- AI & Machine Learning Model Serving: Serving PyTorch, TensorFlow, Scikit-learn, and Hugging Face inference endpoints.
- Automatic OpenAPI & Swagger Documentation: Generating interactive documentation with zero manual configuration.
- Data Validation & Type-Safe Payloads: Validating query parameters, paths, headers, and request bodies with Pydantic v2.
Quick Start
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
class Item(BaseModel):
name: str
price: float
@app.post("/items/")
async def create_item(item: Item):
return {"name": item.name, "price": item.price}Core Concepts
Async Route Handlers & Pydantic v2 Models
Strict payload parsing and serialization:
from fastapi import FastAPI, HTTPException, status, Depends
from pydantic import BaseModel, EmailStr, Field
from typing import List
app = FastAPI(title="Catalog API", version="2.0.0")
class ProductCreate(BaseModel):
name: str = Field(min_length=2, max_length=100)
price: float = Field(gt=0, description="Price in USD")
tags: List[str] = []
class ProductResponse(ProductCreate):
id: int
is_active: bool = True
@app.post("/products", response_model=ProductResponse, status_code=status.HTTP_201_CREATED)
async def create_product(product: ProductCreate):
# Process and persist product
return {
"id": 101,
"name": product.name,
"price": product.price,
"tags": product.tags,
"is_active": True
}Dependency Injection System with Depends
Reusing database sessions, authentication, and service clients:
from fastapi import Header, HTTPException
async def verify_api_key(x_api_key: str = Header(...)):
if x_api_key != "secret-internal-key":
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Invalid API Key"
)
return x_api_key
@app.get("/secure-metrics")
async def get_metrics(api_key: str = Depends(verify_api_key)):
return {"status": "authorized", "system_load": 0.42}Lifespan Events & Async Resource Management
Initializing ML models, database connection pools, and Redis caches:
from contextlib import asynccontextmanager
class ResourceState:
db_pool = None
state = ResourceState()
@asynccontextmanager
async def lifespan(app: FastAPI):
# Startup: Initialize connections
print("Connecting to database pool...")
state.db_pool = "connected_pool_instance"
yield
# Shutdown: Clean up connections
print("Closing database pool...")
state.db_pool = None
app = FastAPI(lifespan=lifespan)Common Patterns
Dependency Injection with Database Session
Problem: Replicating database connection creation and teardown across every API route.
Solution:
Use Depends() with generator context management:
from fastapi import FastAPI, Depends, HTTPException
from sqlalchemy.orm import Session
from .database import get_db
from . import models, schemas
app = FastAPI()
@app.get("/items/{item_id}", response_model=schemas.ItemResponse)
def read_item(item_id: int, db: Session = Depends(get_db)):
db_item = db.query(models.Item).filter(models.Item.id == item_id).first()
if db_item is None:
raise HTTPException(status_code=404, detail="Item not found")
return db_itemBest Practices
Do:
- Migrate to FastAPI lifespan handlers (
@asynccontextmanager) instead of deprecated@app.on_event("startup"). - Leverage Pydantic v2 for up to 5x-10x faster schema serialization and parsing.
- Define synchronous
def(instead ofasync def) for blocking operations so FastAPI executes them in the worker threadpool. - Structure routes with
APIRouterto maintain clean domain separation.
Don't:
- Perform blocking CPU or I/O calls directly inside
async defhandlers; useasyncio.to_thread. - Return raw database entities; map them through Pydantic
response_modelschemas. - Hardcode CORS origins to
["*"]when authentication credentials are allowed.
Troubleshooting
| Error | Cause | Solution |
422 Unprocessable Entity | Inbound request payload failed Pydantic schema validation. | Inspect response body details to see field validation failures. |
RuntimeError: Task attached to a different loop | Blocking synchronous database driver used in async async def route. | Use def instead of async def for sync I/O, or switch to async driver (asyncpg/aiomysql). |
AttributeError: 'NoneType' object has no attribute 'id' | Query returned None and code attempted to access attribute without check. | Guard with if not item: raise HTTPException(404). |
References
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

