FastAPI Expert
Async Python APIs with FastAPI + Pydantic V2, production-grade.
When to use
REST APIs with FastAPI; Pydantic V2 validation schemas; async DB (SQLAlchemy); JWT auth; WebSocket endpoints; OpenAPI docs; performance tuning.
Core workflow
- Analyze — endpoints, data models, auth needs.
- Design schemas — Pydantic V2 models.
- Implement — async endpoints with dependency injection.
- Secure — auth, authorization, rate limiting.
- Test — async tests (pytest + httpx); verify
/docs. Checkpoint each step: schemas validate, endpoints return correct codes.
Key pattern
DbDep = Annotated[AsyncSession, Depends(get_db)]
@router.post("/users/", response_model=UserResponse, status_code=201)
async def create_user(payload: UserCreate, db: DbDep) -> UserResponse:
if await crud.get_user_by_email(db, payload.email):
raise HTTPException(status_code=409, detail="Email already registered")
return await crud.create_user(db, payload)
async def get_user_by_email(db: AsyncSession, email: str) -> User | None:
res = await db.execute(select(User).where(User.email == email))
return res.scalar_one_or_none()
Constraints
MUST: Pydantic V2 models for I/O validation; async endpoints + async SQLAlchemy; dependency injection (Depends); response_model on endpoints; explicit HTTP status codes; hash passwords; async tests.
MUST NOT: blocking I/O in async routes; raw SQL without params; leak ORM models in responses (use response schemas); store secrets in code; skip input validation.
Output
- Pydantic schemas. 2. Async routers + CRUD layer. 3. Auth/security wiring. 4. pytest+httpx tests. 5. Brief note on async/validation decisions.
Knowledge
FastAPI, Pydantic V2, async/await, SQLAlchemy (async), Alembic, JWT (python-jose/passlib), WebSockets, dependency injection, OpenAPI/Swagger, pytest, httpx.
1---2name: fastapi-expert3description: "Use when building high-performance async Python APIs with FastAPI and Pydantic V2. Invoke for REST endpoints, Pydantic models, async SQLAlchemy, JWT auth, WebSocket endpoints, OpenAPI docs. Triggers: FastAPI, Pydantic, async Python, Python API, REST API Python, SQLAlchemy async, JWT authentication, OpenAPI, Swagger Python."4version: 1.0.05license: MIT6tags: [fastapi, pydantic, async, python, sqlalchemy, jwt, websocket, openapi]7source: https://github.com/jeffallan/claude-skills/tree/main/skills/fastapi-expert8derived_from: awesomeclaude9metadata:10 source: https://skillmd.com/skills/aashutosh396/fastapi-expert11---1213# FastAPI Expert1415Async Python APIs with FastAPI + Pydantic V2, production-grade.1617## When to use1819REST APIs with FastAPI; Pydantic V2 validation schemas; async DB (SQLAlchemy); JWT auth; WebSocket endpoints; OpenAPI docs; performance tuning.2021## Core workflow22231. **Analyze** — endpoints, data models, auth needs.242. **Design schemas** — Pydantic V2 models.253. **Implement** — async endpoints with dependency injection.264. **Secure** — auth, authorization, rate limiting.275. **Test** — async tests (pytest + httpx); verify `/docs`. Checkpoint each step: schemas validate, endpoints return correct codes.2829## Key pattern3031```python32DbDep = Annotated[AsyncSession, Depends(get_db)]3334@router.post("/users/", response_model=UserResponse, status_code=201)35async def create_user(payload: UserCreate, db: DbDep) -> UserResponse:36 if await crud.get_user_by_email(db, payload.email):37 raise HTTPException(status_code=409, detail="Email already registered")38 return await crud.create_user(db, payload)3940async def get_user_by_email(db: AsyncSession, email: str) -> User | None:41 res = await db.execute(select(User).where(User.email == email))42 return res.scalar_one_or_none()43```4445## Constraints4647MUST: Pydantic V2 models for I/O validation; async endpoints + async SQLAlchemy; dependency injection (`Depends`); `response_model` on endpoints; explicit HTTP status codes; hash passwords; async tests.48MUST NOT: blocking I/O in async routes; raw SQL without params; leak ORM models in responses (use response schemas); store secrets in code; skip input validation.4950## Output51521. Pydantic schemas. 2. Async routers + CRUD layer. 3. Auth/security wiring. 4. pytest+httpx tests. 5. Brief note on async/validation decisions.5354## Knowledge5556FastAPI, Pydantic V2, async/await, SQLAlchemy (async), Alembic, JWT (python-jose/passlib), WebSockets, dependency injection, OpenAPI/Swagger, pytest, httpx.