Token导航 LogoToken导航TokenDH.com
开发需要联网clawhub未标认证来源可访问clear审计通过

fastapiFastAPI 开发

Agent Skill

用于辅助 Python 项目开发、测试、依赖管理和常见框架工作流。它适合让 Agent 阅读 Python 代码、定位测试问题、整理运行命令、生成脚本或分析数据处理逻辑。使用时需要确认项目虚拟环境、依赖版本和测试入口;涉及执行脚本、读写文件、访问数据库或调用外部 API 时,应先明确运行目录和输入输出范围,避免误改生产数据。

总安装

71,760

周安装

3,051

GitHub Stars

5

下载量

25,140
OpenClaw

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

MIT-0

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:fastapi(FastAPI 开发)
来源仓库:https://github.com/ivangdavila/fastapi
安装命令:
openclaw skills install fastapi
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 OpenClaw 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

ClawHubOpenClaw
openclaw skills install fastapi

简介

通过类型提示、验证和异步支持构建高性能 Python API。

  • 适用于 OpenClaw 中辅助 Python 项目开发、测试与依赖管理。
  • 可帮助阅读代码、定位测试问题或生成运行脚本。
  • 安装前需确认虚拟环境与依赖版本兼容性。fastapi 属于开发类 Skill,可作为该场景下的辅助能力补充。
  • 执行脚本或读写文件时应限定目录范围,避免误改生产数据。

SKILL.md

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"]}}

FastAPI Patterns

Async Traps

  • Mixing sync database drivers (psycopg2, PyMySQL) in async endpoints blocks the event loop — use async drivers (asyncpg, aiomysql) or run sync code in run_in_executor
  • time.sleep() in async endpoints blocks everything — use await asyncio.sleep() instead
  • CPU-bound work in async endpoints starves other requests — offload to ProcessPoolExecutor or background workers
  • Async endpoints calling sync functions that do I/O still block — the entire call chain must be async

Pydantic Validation

  • Default values in models become shared mutable state: items: 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)
  • Pydantic v2 uses model_validate() not parse_obj(), and model_dump() not .dict() — v1 methods are deprecated
  • Use Annotated[str, Field(min_length=1)] for reusable validated types instead of repeating constraints

Dependency Injection

  • Dependencies run on every request by default — use lru_cache on expensive dependencies or cache in app.state for singletons
  • Depends() without an argument reuses the type hint as the dependency — clean but can confuse readers
  • Nested dependencies form a DAG — if A depends on B and C, and both B and C depend on D, D runs once (cached per-request)
  • yield dependencies for cleanup (DB sessions, file handles) — code after yield runs even if the endpoint raises

Lifespan and Startup

  • @app.on_event("startup") is deprecated — use lifespan async context manager
  • Store shared resources (DB pool, HTTP client) in app.state during lifespan, not as global variables
  • Lifespan runs once per worker process — with 4 Uvicorn workers you get 4 DB pools
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app):
    app.state.db = await create_pool()
    yield
    await app.state.db.close()
app = FastAPI(lifespan=lifespan)

Request/Response

  • Return dict from endpoints, not Pydantic models directly — FastAPI handles serialization and it's faster
  • Use status_code=201 on POST endpoints returning created resources — 200 is the default but semantically wrong
  • Response with media_type="text/plain" for non-JSON responses — returning a string still gets JSON-encoded otherwise
  • Set response_model_exclude_unset=True to omit None fields from response — cleaner API output

Error Handling

  • raise HTTPException(status_code=404) — don't return Response objects for errors, it bypasses middleware
  • Custom exception handlers with @app.exception_handler(CustomError) — but remember they don't catch HTTPException
  • Use detail= for user-facing messages, log the actual error separately — don't leak stack traces

Background Tasks

  • BackgroundTasks runs after the response is sent but still in the same process — not suitable for long-running jobs
  • Tasks execute sequentially in order added — don't assume parallelism
  • If a background task fails, the client never knows — add your own error handling and alerting

Security

  • OAuth2PasswordBearer is for documentation only — it doesn't validate tokens, you must implement that in the dependency
  • CORS middleware must come after exception handlers in middleware order — or errors won't have CORS headers
  • Depends(get_current_user) in path operation, not in router — dependencies on routers affect all routes including health checks

Testing

  • TestClient runs sync even for async endpoints — use httpx.AsyncClient with ASGITransport for true async testing
  • Override dependencies with app.dependency_overrides[get_db] = mock_db — cleaner than monkeypatching
  • TestClient context manager ensures lifespan runs — without with TestClient(app) as client: startup/shutdown hooks don't fire

适合场景

01

OpenClaw 用户查找和安装 Skill 时

02

用户想查找某类 Agent Skill 时

03

需要根据任务场景推荐可安装能力包时

04

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

补充不同宿主或平台的使用分布数据

能力 5

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

OpenClaw

87.37%
按下载量换算21,965

安全审计

VirusTotal

通过

ClawScan

通过

Static analysis

未展示

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills