Build fast, production-ready Python APIs with type hints, validation, and async support.
数据来源:ClawHub。 在 ClawSkills 查看
选择你使用的 Agent
方法一:命令行安装(推荐)
推荐(无需提前安装 clawhub)
npx clawhub@latest --dir ~/.claude/skills install fastapi或使用 clawhub CLI(需提前安装)
clawhub --dir ~/.claude/skills install fastapi⚠️ 需要 Node.js 18+,没有 Node?请使用下方方法二直接下载 ZIP。 安装 Node.js →
方法二:手动下载安装(无需 Node)
下载 ZIP,解压后将文件夹放到以下路径,重启 Agent 即可:
安装路径
~/.claude/skills/fastapi/💡解压后将文件夹放到上方路径,重启 Agent 即可生效
--- name: FastAPI description: Build fast, production-ready Python APIs with type hints, validation, and async support. metadata: {"clawdbot":{"emoji":"⚡","requires":{"bins":["python3"]},"os":["linux","darwin","win32"]}} ---
run_in_executortime.sleep() in async endpoints blocks everything — use await asyncio.sleep() insteadProcessPoolExecutor or background workersitems: list = [] shares the same list across requests — use Field(default_factory=list)Optional[str] doesn't make a field optional in the request — add = None or use Field(default=None)model_validate() not parse_obj(), and model_dump() not .dict() — v1 methods are deprecatedAnnotated[str, Field(min_length=1)] for reusable validated types instead of repeating constraintslru_cache on expensive dependencies or cache in app.state for singletonsDepends() without an argument reuses the type hint as the dependency — clean but can confuse readersyield dependencies for cleanup (DB sessions, file handles) — code after yield runs even if the endpoint raises@app.on_event("startup") is deprecated — use lifespan async context managerapp.state during lifespan, not as global variablesfrom contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app):
app.state.db = await create_pool()
yield
await app.state.db.close()
app = FastAPI(lifespan=lifespan)
dict from endpoints, not Pydantic models directly — FastAPI handles serialization and it's fasterstatus_code=201 on POST endpoints returning created resources — 200 is the default but semantically wrongResponse with media_type="text/plain" for non-JSON responses — returning a string still gets JSON-encoded otherwiseresponse_model_exclude_unset=True to omit None fields from response — cleaner API outputraise HTTPException(status_code=404) — don't return Response objects for errors, it bypasses middleware@app.exception_handler(CustomError) — but remember they don't catch HTTPExceptiondetail= for user-facing messages, log the actual error separately — don't leak stack tracesBackgroundTasks runs after the response is sent but still in the same process — not suitable for long-running jobsOAuth2PasswordBearer is for documentation only — it doesn't validate tokens, you must implement that in the dependencyDepends(get_current_user) in path operation, not in router — dependencies on routers affect all routes including health checksTestClient runs sync even for async endpoints — use httpx.AsyncClient with ASGITransport for true async testingapp.dependency_overrides[get_db] = mock_db — cleaner than monkeypatchingTestClient context manager ensures lifespan runs — without with TestClient(app) as client: startup/shutdown hooks don't fire安装 FastAPI 后,可以对 AI 说这些话来触发它
Help me get started with FastAPI
Explains what FastAPI does, walks through the setup, and runs a quick demo based on your current project
Use FastAPI to build fast, production-ready Python APIs with type hints, validatio...
Invokes FastAPI with the right parameters and returns the result directly in the conversation
What can I do with FastAPI in my developer & devops workflow?
Lists the top use cases for FastAPI, with example commands for each scenario
将技能文件夹放到 ~/.claude/skills/fastapi/ 目录(个人级,所有项目可用),或 .claude/skills/fastapi/(项目级)。重启 AI 客户端后,用 /fastapi 主动调用,或让 AI 根据上下文自动发现并使用。
FastAPI 支持 Claude、Cursor、OpenClaw,可与这些 AI 平台无缝集成,扩展其能力。
FastAPI 可免费安装使用。请查阅仓库了解许可证信息。
Build fast, production-ready Python APIs with type hints, validation, and async support.
FastAPI 属于「Developer & DevOps」分类,该分类的技能帮助 AI 智能体在此领域执行专业任务。
Automate my developer & devops tasks using FastAPI
Identifies repetitive steps in your workflow and sets up FastAPI to handle them automatically