fastapi-best-practices
10
总安装量
4
周安装量
#30207
全站排名
安装命令
npx skills add https://github.com/ahmed6ww/ax-agents --skill fastapi-best-practices
Agent 安装分布
opencode
3
github-copilot
3
codex
3
gemini-cli
3
kimi-cli
2
cursor
2
Skill 文档
FastAPI Best Practices
Comprehensive production-grade best practices for FastAPI applications. Contains rules across 7 categories to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Setting up a new FastAPI project structure
- Implementing async routes and handling blocking I/O
- Designing Pydantic models and validation logic
- Structuring dependencies for reusable validation and injection
- Integrating databases with SQLAlchemy and Alembic
- Writing tests and configuring CI/CD tooling
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Async & Concurrency | CRITICAL | async- |
| 2 | Project Structure | HIGH | structure- |
| 3 | Pydantic Patterns | HIGH | pydantic- |
| 4 | Dependency Injection | MEDIUM-HIGH | dependency- |
| 5 | Database & Storage | MEDIUM | db- |
| 6 | REST & API Design | MEDIUM | api- |
| 7 | Testing & Tooling | LOW-MEDIUM | tooling- |
| 8 | Code Maintenance | LOW | maintenance- |
| 9 | Performance Optimization | MEDIUM | performance- |
| 10 | TDD Strategy | HIGH | tdd- |
Quick Reference
1. Async & Concurrency (CRITICAL)
async-io-intensive– Useasync deffor awaitables,deffor blocking I/Oasync-cpu-intensive– Offload CPU work to multiprocessing/Celeryasync-sync-sdk– Userun_in_threadpoolfor sync SDKs in async routes
2. Project Structure (HIGH)
structure-domain-driven– Organize by domain (src/{domain}), not file type
3. Pydantic Patterns (HIGH)
pydantic-validation– Use built-in regex, enums, etc.pydantic-custom-base– Use custom base model for global serializationpydantic-config– Split BaseSettings by domainpydantic-value-error– Raise ValueError for validation errors
4. Dependency Injection (MEDIUM-HIGH)
dependency-validation– Use Depends for DB-backed validationdependency-chaining– Chain dependencies for reusedependency-decoupling– Decouple into small reusable unitsdependency-async– Prefer async dependencies
5. Database & Storage (MEDIUM)
db-naming-conventions– Strict naming (snake_case, singular, etc.)db-index-naming– Explicit index naming conventionsdb-sql-first– Prefer SQL for complex data logicdb-migrations– Static, descriptive, reversible migrations
6. REST & API Design (MEDIUM)
api-path-naming– Consistent path vars for dependency reuseapi-response-serialization– Minimize serialization overheadapi-docs-hiding– Hide docs in productionapi-docs-customization– Detailed OpenAPI metadata
7. Testing & Tooling (LOW-MEDIUM)
tooling-test-client– Use AsyncClient/httpx for teststooling-linter– Use Ruff for all linting
8. New Capabilities (Merged)
- Scripts: Helper scripts available in
scripts/(e.g.,run_ruff.py). - References: Additional guides in
references/(e.g.,quad_strategy.md). - TDD: Explicit testing strategies in
rules/tdd-strategy.md.
How to Use
Read individual rule files for detailed explanations and code examples:
rules/async-io-intensive.md
rules/structure-domain-driven.md
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md