← 返回 Skills 市场
2274
总下载
5
收藏
22
当前安装
1
版本数
在 OpenClaw 中安装
/install fastapi
功能描述
Build fast, production-ready Python APIs with type hints, validation, and async support.
使用说明 (SKILL.md)
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 — useawait asyncio.sleep()instead- CPU-bound work in async endpoints starves other requests — offload to
ProcessPoolExecutoror 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 — useField(default_factory=list) Optional[str]doesn't make a field optional in the request — add= Noneor useField(default=None)- Pydantic v2 uses
model_validate()notparse_obj(), andmodel_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_cacheon 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)
yielddependencies for cleanup (DB sessions, file handles) — code after yield runs even if the endpoint raises
Lifespan and Startup
@app.on_event("startup")is deprecated — uselifespanasync context manager- Store shared resources (DB pool, HTTP client) in
app.stateduring 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
dictfrom endpoints, not Pydantic models directly — FastAPI handles serialization and it's faster - Use
status_code=201on POST endpoints returning created resources — 200 is the default but semantically wrong Responsewithmedia_type="text/plain"for non-JSON responses — returning a string still gets JSON-encoded otherwise- Set
response_model_exclude_unset=Trueto 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
BackgroundTasksruns 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
OAuth2PasswordBeareris 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
TestClientruns sync even for async endpoints — usehttpx.AsyncClientwithASGITransportfor true async testing- Override dependencies with
app.dependency_overrides[get_db] = mock_db— cleaner than monkeypatching TestClientcontext manager ensures lifespan runs — withoutwith TestClient(app) as client:startup/shutdown hooks don't fire
安全使用建议
This skill appears to be a harmless FastAPI best-practices guide. A few practical notes before installing/using it: (1) the skill is instruction-only and will not install FastAPI or its dependencies for you — if you run the example code you must install packages in a controlled environment; (2) the skill's source and homepage are listed as unknown/none, so if provenance matters prefer guidance from known authors or official docs; (3) if you plan to let an agent execute code snippets from this skill, run them in an isolated sandbox (container/venv) to avoid accidental access to your files or secrets. Overall the skill is coherent with its description and does not request excessive access.
功能分析
Type: OpenClaw Skill
Name: fastapi
Version: 1.0.0
The provided skill bundle contains standard metadata and a comprehensive markdown document detailing best practices and common patterns for FastAPI development. There are no indications of malicious intent, prompt injection attempts, data exfiltration, unauthorized command execution, or any other harmful behaviors. The content is purely informational and educational, aligning with the stated purpose of a skill bundle.
能力评估
Purpose & Capability
The name/description match the SKILL.md content (FastAPI best-practices and patterns). The only declared runtime requirement is python3, which is reasonable for Python examples; nothing else (credentials, unrelated binaries, or config paths) is requested.
Instruction Scope
SKILL.md contains coding guidance and example snippets only. It does not instruct the agent to read arbitrary files, access environment variables, call external endpoints, or exfiltrate data. There are no open-ended directives that would give the agent broad discretion to collect unrelated context.
Install Mechanism
No install spec is provided and there are no code files. As an instruction-only skill it does not write files to disk or download external archives, which minimizes install-time risk.
Credentials
The skill declares no required environment variables, credentials, or config paths. Nothing requested is disproportionate to the stated purpose of giving FastAPI guidance.
Persistence & Privilege
always is false and the skill does not request persistent presence or system-wide configuration changes. Model invocation is allowed (platform default) but that is consistent with an advice/help skill and is not combined with other red flags.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install fastapi - 安装完成后,直接呼叫该 Skill 的名称或使用
/fastapi触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
Initial release
元数据
常见问题
FastAPI 是什么?
Build fast, production-ready Python APIs with type hints, validation, and async support. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 2274 次。
如何安装 FastAPI?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install fastapi」即可一键安装,无需额外配置。
FastAPI 是免费的吗?
是的,FastAPI 完全免费(开源免费),可自由下载、安装和使用。
FastAPI 支持哪些平台?
FastAPI 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(linux, darwin, win32)。
谁开发了 FastAPI?
由 Iván(@ivangdavila)开发并维护,当前版本 v1.0.0。
推荐 Skills