FastAPI Development Best Practices
Comprehensive modern API development framework with 100+ individual rules across 40 rule categories covering the complete FastAPI ecosystem. Fully aligned with official FastAPI documentation from basic parameters to advanced security, covering async programming, validation, security, API design, web standards, application architecture, debugging, and production deployment. Designed for production-ready FastAPI applications with proper async/await handling, type safety, and scalable architecture.
When to Apply
Reference these guidelines when:
- Building new FastAPI applications or APIs
- Implementing async endpoints and background tasks
- Designing data models with Pydantic
- Implementing authentication and authorization
- Writing tests for async applications
- Deploying FastAPI applications to production
- Optimizing async performance and concurrency
Rule Categories by Priority
| Priority | Category | Impact | Files | Individual Rules | Prefix |
| --- | --- | --- | --- | --- | --- | --- |
| 1 | Async & Concurrency | CRITICAL | 4 | 12 | async- |
| 2 | Security & Authentication | CRITICAL | 3 | 8 | security- |
| 3 | Validation & Models | HIGH | 1 | 5 | validation- |
| 4 | Core Parameters | HIGH | 4 | 12 | core- |
| 5 | API Design | HIGH | 6 | 15 | api- |
| 6 | Data Handling | MEDIUM-HIGH | 2 | 8 | data- |
| 7 | Application Structure | MEDIUM-HIGH | 1 | 5 | app- |
| 8 | Database & ORM | MEDIUM-HIGH | 1 | 4 | db- |
| 9 | Testing | MEDIUM-HIGH | 1 | 4 | testing- |
| 10 | Performance | MEDIUM | 2 | 4 | perf- |
| 11 | Deployment | MEDIUM | 1 | 3 | deploy- |
| 12 | Documentation | MEDIUM | 1 | 2 | docs- |
| 13 | Web & HTTP | MEDIUM | 4 | 10 | web- |
| 14 | Development & Debug | MEDIUM | 1 | 6 | dev- |
| 15 | Response Handling | MEDIUM | 3 | 8 | response- |
| 16 | Documentation & Examples | MEDIUM | 2 | 6 | docs- |
| 17 | Advanced Patterns | LOW | 4 | 9 | advanced- |
| Total | 17 Categories | | 40 Files | 100+ Rules | |
Quick Reference
1. Async & Concurrency (CRITICAL)
async-endpoints: Always use async def for endpoint functionsasync-dependencies: Use async dependency injection properlyasync-database: Handle async database operations correctlyasync-background: Implement background tasks with proper async handling
2. Security & Authentication (CRITICAL)
security-jwt: Implement JWT tokens securelysecurity-cors: Configure CORS properly for productionsecurity-rate-limiting: Implement rate limiting for APIs
3. Validation & Models (HIGH)
validation-pydantic: Use Pydantic models for all data validation
4. Core Parameters (HIGH)
path-parameters: Handle dynamic URL routing with type safetyquery-parameters: Flexible API filtering with validationrequest-body: Structured data submission with Pydanticresponse-models: Consistent API responses with documentation
5. API Design (HIGH)
api-restful: Follow RESTful API design principlesapi-pagination: Add pagination for large datasetsapi-error-handling: Return proper validation error responsesapi-file-handling: Handle file uploads securelyapi-versioning: Implement API versioning strategiesstreaming-responses: Handle large data and real-time responses
6. Database & ORM (MEDIUM-HIGH)
async-database: Handle async database operations correctly
7. Testing (MEDIUM-HIGH)
testing-async: Set up proper async testing
8. Performance (MEDIUM)
- Response caching and concurrency limits
9. Deployment (MEDIUM)
deploy-production: Production server setup
10. Documentation (MEDIUM)
- OpenAPI documentation setup
11. Web & HTTP (MEDIUM)
cookie-parameters: Client state management and authenticationheader-parameters: Metadata passing and API versioningstatic-files: Serving static assets and file resourceslifespan-events: Application initialization and cleanup
12. Data Handling (MEDIUM-HIGH)
form-data-handling: HTML form processing and validationextra-data-types: Advanced data types and JSON encoding
13. Application Structure (MEDIUM-HIGH)
bigger-applications: Multi-file application organization
14. Development & Debug (MEDIUM)
debugging-fastapi: Development debugging and troubleshooting
15. Response Handling (MEDIUM)
custom-response-classes: HTML, CSV, XML, streaming responsesresponse-cookies: Secure cookie management, sessions, preferencesresponse-headers: Security headers, caching, CORS, metadata
16. Documentation & Examples (MEDIUM)
request-examples: Comprehensive request model examplesmetadata-docs: Custom documentation URLs and API metadata
17. Advanced Patterns (LOW)
websocket-support: Real-time bidirectional communicationbody-updates: Partial updates and PATCH operationsmonitoring-observability: Comprehensive monitoring setuppath-operation-config: Advanced endpoint configuration
Quick Start
- 📖 Overview:
skills/fastapi-skill/SKILL.md - 📚 Complete Reference:
skills/fastapi-skill/AGENTS.md - 🔍 Specific Rules:
skills/fastapi-skill/rules/[category]-[rule-name].md