skills/python-skills/fastapi/SKILL.md
Provides comprehensive guidance for FastAPI framework including routing, request validation, dependency injection, async operations, OpenAPI documentation, and database integration. Use when the user asks about FastAPI, needs to create REST APIs, or build high-performance Python web services.
npx skillsauth add teachingai/agent-skills fastapiInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Use this skill whenever the user wants to:
FastAPI() and define route handlers/docsfrom fastapi import FastAPI, HTTPException, Depends
from pydantic import BaseModel
from datetime import datetime
app = FastAPI(title="My API", version="1.0.0")
# Request/Response models
class ItemCreate(BaseModel):
name: str
price: float
description: str | None = None
class ItemResponse(ItemCreate):
id: int
created_at: datetime
# Dependency example
async def get_db():
db = SessionLocal()
try:
yield db
finally:
db.close()
# Route handlers
@app.post("/items/", response_model=ItemResponse, status_code=201)
async def create_item(item: ItemCreate, db=Depends(get_db)):
db_item = Item(**item.model_dump())
db.add(db_item)
db.commit()
return db_item
@app.get("/items/{item_id}", response_model=ItemResponse)
async def get_item(item_id: int, db=Depends(get_db)):
item = db.query(Item).get(item_id)
if not item:
raise HTTPException(status_code=404, detail="Item not found")
return item
# Run the server
uvicorn main:app --reload
# Interactive docs available at http://localhost:8000/docs
from fastapi.security import OAuth2PasswordBearer
oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token")
@app.get("/users/me")
async def read_current_user(token: str = Depends(oauth2_scheme)):
user = verify_token(token)
if not user:
raise HTTPException(status_code=401, detail="Invalid token")
return user
/docs, /redoc) for API explorationBackgroundTasks for non-blocking operations like email sendingfastapi, async API, Pydantic, OpenAPI, dependency injection, Python web, REST API, uvicorn
development
Guidance for Next.js using the official docs at nextjs.org/docs. Use when the user needs Next.js concepts, configuration, routing, data fetching, or API reference details.
tools
Provides comprehensive guidance for Flask framework including routing, templates, forms, database integration, extensions, and deployment. Use when the user asks about Flask, needs to create web applications, implement routes, or build Python web services.
development
Provides comprehensive guidance for Django framework including models, views, templates, forms, admin, REST framework, and deployment. Use when the user asks about Django, needs to create web applications, implement models and views, or build Django REST APIs.
tools
用于通过 Pencil MCP 读取/修改 .pen 设计文件并校验布局。用户提到 pencil/.pen/设计稿编辑、需要列出工具或执行 batch_get/batch_design 时调用。