Awesome-omni-skill fastapi
FastAPI Python framework. Covers REST APIs, validation, dependencies, security. Keywords: Pydantic, async, OAuth2, JWT.
install
source · Clone the upstream repo
git clone https://github.com/diegosouzapw/awesome-omni-skill
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/diegosouzapw/awesome-omni-skill "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/development/fastapi-majiayu000" ~/.claude/skills/diegosouzapw-awesome-omni-skill-fastapi-50fead && rm -rf "$T"
manifest:
skills/development/fastapi-majiayu000/SKILL.mdsource content
FastAPI
This skill provides comprehensive guidance for building APIs with FastAPI.
Quick Navigation
| Topic | Reference |
|---|---|
| Getting started | |
| Path parameters | |
| Query parameters | |
| Request body | |
| Validation | |
| Body advanced | |
| Cookies/Headers | |
| Pydantic models | |
| Forms/Files | |
| Error handling | |
| Path config | |
| Dependencies | |
| Security | |
| Middleware | |
| CORS | |
| Database | |
| Project structure | |
| Background tasks | |
| Metadata/Docs | |
| Testing | |
| Advanced responses | |
| WebSockets | |
| Templates | |
| Settings/Env vars | |
| Lifespan events | |
| OpenAPI advanced | |
When to Use
- Creating REST APIs with Python
- Adding endpoints with automatic validation
- Implementing OAuth2/JWT authentication
- Working with Pydantic models
- Adding dependency injection
- Configuring CORS, middleware
- Uploading files, handling forms
- Testing API endpoints
Installation
pip install "fastapi[standard]" # Full with uvicorn pip install fastapi # Minimal pip install python-multipart # For forms/files
Quick Start
from fastapi import FastAPI app = FastAPI() @app.get("/") def read_root(): return {"Hello": "World"} @app.get("/items/{item_id}") def read_item(item_id: int, q: str | None = None): return {"item_id": item_id, "q": q}
Run:
fastapi dev main.py
Core Patterns
Type-Safe Parameters
from typing import Annotated from fastapi import Path, Query @app.get("/items/{item_id}") def read_item( item_id: Annotated[int, Path(ge=1)], q: Annotated[str | None, Query(max_length=50)] = None ): return {"item_id": item_id, "q": q}
Request Body with Validation
from pydantic import BaseModel, Field class Item(BaseModel): name: str = Field(min_length=1, max_length=100) price: float = Field(gt=0) @app.post("/items/", response_model=Item) def create_item(item: Item): return item
Dependencies
from fastapi import Depends async def get_db(): db = SessionLocal() try: yield db finally: db.close() @app.get("/users/") def list_users(db: Annotated[Session, Depends(get_db)]): return db.query(User).all()
Authentication
from fastapi.security import OAuth2PasswordBearer oauth2_scheme = OAuth2PasswordBearer(tokenUrl="token") async def get_current_user(token: Annotated[str, Depends(oauth2_scheme)]): return decode_token(token) @app.get("/users/me") def read_me(user: Annotated[User, Depends(get_current_user)]): return user
API Documentation
- Swagger UI:
/docs - ReDoc:
/redoc - OpenAPI:
/openapi.json
Best Practices
- Use
for parametersAnnotated[Type, ...] - Define Pydantic models for request/response
- Use
for output filteringresponse_model - Add
for proper HTTP codesstatus_code - Use
for API organizationtags - Add
at router/app level for authdependencies
Prohibitions
- ❌ Return raw database models (use response models)
- ❌ Store passwords in plain text (use bcrypt/passlib)
- ❌ Mix
withBody
/Form
in same endpointFile - ❌ Use sync blocking I/O in async endpoints
- ❌ Skip HTTPException for error handling
Links
- Docs: https://fastapi.tiangolo.com/
- Tutorial: https://fastapi.tiangolo.com/tutorial/
- Advanced: https://fastapi.tiangolo.com/advanced/