FastAPI Cursor Rules
Cursor rules for FastAPI: Pydantic models, dependency injection, async patterns, and production API best practices.
- Use Pydantic v2 models for all request/response schemas; separate input and output schemas - Leverage FastAPI dependency injection for auth, DB sessions, and shared logic - Use async def for all endpoints that do I/O (database, HTTP calls) - Return appropriate HTTP status codes; use HTTPException with detail messages - Add response_model to all endpoints for automatic serialization and docs - Use APIRouter to organize routes by feature; avoid everything in main.py - Implement lifespan context manager for startup/shutdown (not deprecated events) - Use BackgroundTasks for fire-and-forget work that shouldn't block responses
How to use with Cursor
Create a `.cursorrules` file in your project root and paste these rules. Cursor reads this automatically on every AI interaction.
Related Rules
Python Cursor Rules
Best Cursor AI coding rules for Python development. Enforce type hints, PEP 8, Pythonic patterns, and modern Python best practices in your .cursorrules file.
TypeScript Cursor Rules
Cursor rules for TypeScript: enforce strict mode, eliminate any types, and write type-safe code with these .cursorrules configurations.
React Cursor Rules
Cursor rules for React: component patterns, hooks best practices, performance optimization, and clean state management conventions.
Next.js Cursor Rules
Cursor rules for Next.js App Router: server components, data fetching, routing, and deployment best practices.