Skip to content

FastAPI done right. Async patterns, dependency injection, Pydantic v2, middleware, background tasks.

License

Notifications You must be signed in to change notification settings

ofershap/fastapi-best-practices

Repository files navigation

FastAPI Best Practices

License: MIT Skills

FastAPI done right. Async/sync endpoint selection, Depends() for dependency injection, Pydantic v2 models, lifespan context managers, BackgroundTasks, APIRouter, Annotated types, and production project structure.

AI coding assistants make every endpoint async, use global variables instead of Depends(), generate Pydantic v1 decorators, and put all routes in a single file. This plugin enforces the patterns that make FastAPI production-ready.

Install

Cursor / Claude Code / Windsurf

npx skills add ofershap/fastapi-best-practices

Or copy skills/ into your .cursor/skills/ or .claude/skills/ directory.

What's Included

Type Name Description
Skill fastapi-best-practices 10 rules for async patterns, Depends(), Pydantic v2, lifespan, APIRouter, and more
Rule best-practices Always-on behavioral rule that enforces current FastAPI patterns
Command /audit Scan your codebase for FastAPI anti-patterns

What Agents Get Wrong

What the agent writes What FastAPI best practice is
async def for everything async def for I/O, def for CPU-bound
Global db variable Depends(get_db) dependency injection
@validator, class Config field_validator, ConfigDict (Pydantic v2)
@app.on_event("startup") lifespan context manager
All routes in main.py APIRouter with organized modules
asyncio.create_task() BackgroundTasks for fire-and-forget work
return {"error": "not found"} response_model + status.HTTP_404_NOT_FOUND

Related Plugins


If this helped your workflow, a star helps others find it.

Author

Made by ofershap

LinkedIn GitHub

License

MIT

About

FastAPI done right. Async patterns, dependency injection, Pydantic v2, middleware, background tasks.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

 

Packages

No packages published

Contributors 2

  •  
  •