fastapi-patterns
FastAPI 最佳实践:项目结构、Pydantic v2 schema、依赖注入、异步处理器、身份认证、授权、事务性服务层,以及使用 httpx 和 pytest 测试。适用于构建或审查 FastAPI 应用中的 Pydantic schema、依赖、异步处理器、认证或测试。
译文已校对查看英文原文
FastAPI best practices covering project structure, Pydantic v2 schemas, dependency injection, async handlers, authentication, authorization, transactional service layers, and testing with httpx and pytest. Use when building or reviewing FastAPI apps — Pydantic schemas, dependencies, async handlers, auth, or tests.
适用对象:软件开发与测试。自动收录 · 待核查。
原作者说明节选
从固定版本的 SKILL.md 提取,保留原文语言。以下内容属于作者说明,本站尚未验证安装、兼容或运行结果。
查看英文原文
原文涵盖的主题
- FastAPI Patterns
- Project Structure
- App Factory and Lifespan
- Configuration with pydantic-settings
- Pydantic Schemas (v2)
- Dependency Injection
- Router and Endpoint Design
- Service Layer
Modern, production-grade FastAPI development: project layout, Pydantic v2 schemas, dependency injection, async patterns, auth, transactional service methods, and testing. -- -- -- -- -- -- Note on Database Design: Application-level unique handling requires an underlying unique database index (e.g., unique=True on your SQLAlchemy mapping attributes). Without underlying constraints, application layer error-catching cannot safely prevent concurrent race conditions. -- -- -- Always declare a typed responsemodel to prevent accidental PII/data leaks and output clean OpenAPI schemas. Consolidate standard middleware dependency injections via type-aliasing: DbDep = Annotated[AsyncSession, Depends(getdb)]. Wrap database mutation boundaries gracefully within transactions inside your service layer, catching structural database errors directly. Parse JWT parameters defensively, expecting potential string/integer cast mismatches from modern payload variations. Enforce deterministic sorting (e.g., .orderby(Model.id)) on all offset/limit paginated endpoints to avoid data skips. Isolate authorization checks from core authentication dependencies to provide precise REST status signals (401 vs 403).
- 来源仓库
- affaan-m/ECC
- 源文件
- pi/core/skills/fastapi-patterns/SKILL.md
- 固定版本
- d2ef2680594f9a17526a6e1a2e18b3d242c5d17b
准备条件
- 本条仅收录原作者的技能元数据;请阅读完整说明,确认依赖、许可与使用条件。
第一件可以尝试的小事
先阅读原作者说明,再决定是否在自己的 AI 工具中使用。
对应 AI 工具说明
作者有说明不等于本站实机验证。没有证据时,不自动标为兼容、安全或免费。
来源与内容状态
本条为自动发现的元数据,尚未完成人工文档核查;适用性与运行结果待核查。
原作者:affaan-m/ECC · 原作者仓库元数据。文档核查:未核查。最近来源检查:2026-11-09T15:01:43.001Z。
分类由名称、说明与路径规则生成,分类不代表已核实适配。
许可与权利归属
MIT。第三方内容及版权归原作者,使用条件以原文为准。
许可原文 ↗本站没有因同步、复制或用户自报成功而将资源标为运行验证通过。
限制与注意事项
- 元数据收录不代表本站已经安装、适配、实测或进行安全审查。