backend-fastapi-python

用于本项目的所有 Python 后端工作:构建 FastAPI 端点、编写服务函数、定义 Pydantic/SQLModel 模式、运行 Alembic 迁移或调试 422 错误。重点涵盖认证与授权模式(如 get_current_user、is_superuser 检查、仅管理员守卫、基于角色的访问控制、Depends() 依赖链)、中间件、后台任务、异步 SQLAlchemy 会话、ORM 关系加载及请求/响应设计。仅在与本项目的 Python API 代码、FastAPI 模式或后端架构相关时激活;不用于前端、Docker、CI/CD 或基础设施。

仓库最近推送
GitHub Stars
138
Forks
16
Issues / PRs
0

安装方式

先用 Prompt 核对来源与依赖。也可下载安装包。

用 AI 助手安装

复制提示词,让助手先核对固定版本和依赖。

查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "backend-fastapi-python":https://skillpi.com/zh/skills/deepskill-cb8ff6ac47512717f7e8509fc424a26f94c958cbdf3b4aa61b74e969958c88ef。安装前核对上游来源和版本:https://github.com/avibebuilder/claude-prime。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。

来源与配置

github.com

配置方式待核实

请查看原始来源中的适用工具、依赖和权限要求。

安装实测待补充

用于本项目的所有 Python 后端工作:构建 FastAPI 端点、编写服务函数、定义 Pydantic/SQLModel 模式、运行 Alembic 迁移或调试 422 错误。重点涵盖认证与授权模式(如 get_current_user、is_superuser 检查、仅管理员守卫、基于角色的访问控制、Depends() 依赖链)、中间件、后台任务、异步 SQLAlchemy 会话、ORM 关系加载及请求/响应设计。仅在与本项目的 Python API 代码、FastAPI 模式或后端架构相关时激活;不用于前端、Docker、CI/CD 或基础设施。

0 下载

介绍来源: third_party · avibebuilder · 0.0.1 参考来源

SkillPi 解读

能完成的任务
翻译待完成,请参阅来源文档。
适合谁
来源文档未说明。
输入和输出
来源文档未说明。
软件、账号及付费要求
来源文档未说明。
限制与区别
来源文档未说明。
实测状态
未测试

文件浏览

在原站浏览文件 ↗

原始 SKILL.md

打开原文 ↗
Frontmatter
name: backend-fastapi-python
description: "Use this skill for any Python backend work in this project: building FastAPI endpoints, writing service functions, defining Pydantic/SQLModel schemas, running Alembic migrations, or debugging 422 errors. Essential for authentication and authorization patterns — setting up get_current_user, is_superuser checks, admin-only guards, role-based access, and dependency injection chains like Depends(). Also covers middleware, background tasks, async SQLAlchemy sessions, ORM relationship loading, and request/response design. Activate whenever the question involves Python API code, FastAPI patterns, or backend architecture in this codebase. Not for frontend, Docker, CI/CD, or infrastructure."

Backend FastAPI Python

Project-specific conventions for FastAPI with SQLModel, pydantic-settings, and async SQLAlchemy.

Architecture Decisions

  1. Services are stateless functions — Not classes. First param is db: AsyncSession.
  2. Generic response wrapper — Always use ApiResponse[T] for consistency.
  3. Dependencies chain — get_current_user -> require_auth -> require_admin.
  4. Module-scoped config — Each module can have its own {module}_config.py.
  5. Error codes for frontend — AppException(status, message, error_code).

Gotchas

  • SQLModel Relationship() fields are NOT included in API responses by default. You must explicitly add them to model_config or use a separate response schema with those fields.
  • AsyncSession.refresh() does not load relationships. After commit, re-query with .options(selectinload(...)) if you need related objects.
  • Pydantic V2 uses model_validator not validator. The @validator decorator is V1 and will break silently or raise deprecation warnings.
  • Depends() in FastAPI creates a NEW instance per request — don't store state in dependency return values expecting it to persist.
  • Background tasks (BackgroundTasks) run AFTER the response is sent. If they fail, the client already got a 200. Use proper task queues (Celery, ARQ) for anything that must not silently fail.
  • Alembic --autogenerate misses: table renames (generates drop+create), index changes on existing columns, and Enum type modifications in PostgreSQL. Always review generated migrations.
  • async def endpoints block the event loop if you call sync I/O inside them. Use run_in_executor for sync libraries or define the endpoint as def (FastAPI runs sync endpoints in a threadpool).
  • HTTPException from FastAPI and HTTPException from Starlette are different classes. Importing the wrong one causes middleware to miss exception handlers.
  • SQLAlchemy's lazy="selectin" on relationships causes N+1 queries in async sessions. Use explicit selectinload() in queries instead.
  • Optional[str] = None in query params makes the field optional. str = None also works but loses type information — prefer the explicit Optional form.
  • When using response_model, FastAPI filters OUT any fields not in the model. If your response is missing data, check that the response model includes all fields, not just the ORM model.

References

When you need... Read
Directory layout file-structure.md
Settings and env vars configuration.md
Database sessions and connections database.md
ORM models models.md
Request/response schemas schemas.md
Router and endpoint patterns routing.md
Service layer patterns services.md
Dependency injection dependencies.md
Middleware setup middleware.md
Error handling error-handling.md
Auth flow example auth.md

版本历史

  1. v1.2.9 GitHub ↗
    原版更新说明

    ## 1.2.9 - 🔧 Enforce sequential skill optimization and tighten description char hint

  2. v1.2.8 GitHub ↗
    原版更新说明

    ## 1.2.8 - 🔧 Stop ask-rule from blocking on facts Claude can look up itself - 🔧 Rebalance discuss skill so pushback is contextual, not default

  3. v1.2.7 GitHub ↗
    原版更新说明

    ## 1.2.7 - ✨ Add humanizer starter skill - 🔧 Note skill description char limits (soft ~650, hard 1024) in skill-creator - 🔧 Sharpen optimus-prime skill scoping and placement guidance

  4. v1.2.6 GitHub ↗
    原版更新说明

    ## 1.2.6 - 🐛 Ignore pycache in self-improve hook

  5. v1.2.5 GitHub ↗
    原版更新说明

    ## 1.2.5 - 🔧 Remove allow-claude-dir hooks as claude-code already fixed it - 🔧 Add .tasks/ to gitignore entries

此处仅展示最近 5 个版本。 在原站查看完整版本历史 ↗

当前收录版本

0.0.1

核对来源版本 ↗

安全与评测信息

质量评测

满分100 · 来自 SkillPi LAB 实验室的评测报告。

场景价值75/100

亮点

  • 提供 FastAPI 后端开发的详细架构决策与规范
  • 涵盖认证授权、依赖注入、ORM 关系加载等关键场景
  • 针对常见陷阱给出明确解决方案
触发精准90/100

亮点

  • 触发词精准限定于 Python 后端工作,排除前端与基础设施
  • 覆盖 FastAPI、SQLModel、Pydantic、Alembic 等核心技术栈
结构规范90/100

亮点

  • 文档结构清晰,含架构决策、陷阱提示与参考链接
  • frontmatter 完整,章节划分合理
执行可靠85/100

亮点

  • 工具来源明确,依赖注入链与错误处理描述准确
  • 提及的异步 SQLAlchemy 与会话管理规范可靠
证据可验 (前四项均值)85/100

取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。

正文静态检测

100 / 100 · skillpi-20261123-no-r3-v1

正文未命中当前规则。

分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。

权限与使用前检查

根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。

未从主文档识别到上述常见操作,不能据此判断无需权限或没有风险。

本站展示提示不会授予权限。涉及文件改动、密钥、外部发送或费用时,仍由你使用的工具按需确认。

安全评级与访问范围

safe · 静态证据核验,不代表运行安全保证。

来源文档未说明。

使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。