Master 1Password: vaults, Watchtower, passkeys, SSH agent, CLI, and family/team administration. Use when getting full value from 1Password personally or administering it for others.
中文简介正在准备中。当前显示原文说明。
FastAPI guidance — typed endpoints, Pydantic validation, dependency injection, async patterns, and production deployment.
中文简介正在准备中。当前显示原文说明。
查看安装方法安装前可以查看交给 AI 代理的指令内容。
FastAPI is a modern Python web framework built on Starlette and Pydantic, where type annotations double as request validation, serialization, and automatic OpenAPI documentation. Declare a Pydantic model and you get parsing, validation errors, and interactive docs for free. Its native async support makes it a strong default for I/O-bound Python APIs. This skill covers designing FastAPI services well: dependency injection, background work, database patterns, and production deployment.
response_model to strip internal fields — never return ORM objects directly.Depends. Dependencies are reusable, composable functions: get_db(), get_current_user(), settings. They can yield (setup/teardown), be cached per-request, and nested. This is the framework's extension mechanism — prefer it over globals and middleware for request-scoped needs.async def endpoints run on the event loop; call async libraries with await. Blocking sync code (most ORMs' sync APIs, requests, heavy CPU work) inside async def endpoints stalls every request — run it in a threadpool via anyio.to_thread or use def endpoints and let FastAPI thread them.computed_field. Keep validation logic in models, not in route handlers.APIRouter with prefixes and tags organizes large APIs; version via URL prefix (/v1) from the start if the API is public.BackgroundTasks run after the response is sent — fine for quick post-response work (sending an email). Anything slow, retryable, or critical belongs in a real queue (Celery, arq, Dramatiq).lifespan context manager (replacing on_event) handles startup/shutdown: connect pools, load models, then yield; cleanup after. One place for resource lifecycle.JSONResponse default; StreamingResponse for large/streaming payloads; FileResponse for downloads — pick deliberately, and set media types explicitly.app/
main.py # app factory, router mounting, middleware
api/v1/ # routers
schemas/ # Pydantic models (request/response)
services/ # business logic
core/ # settings, security, dependencies
create_app() function so tests can construct isolated instances; configure CORS, trusted hosts, and exception handlers there.
def create_app() -> FastAPI:
app = FastAPI(title="Shop API", lifespan=lifespan)
app.include_router(api_router, prefix="/v1")
app.add_middleware(RequestIDMiddleware)
return app
@router.post("/users", response_model=UserOut, status_code=201)
def create_user(payload: UserCreate, db: Session = Depends(get_db)):
...
get_db dependency that yields a session and closes it in finally — one session per request, committed or rolled back by the service layer, never shared across requests.fastapi.security, rate limiting at the proxy, structured logging with request IDs, and /health plus /ready endpoints.
HTTPBearer/OAuth2PasswordBearer schemes so the OpenAPI docs show an Authorize button.TestClient (or async httpx.AsyncClient with ASGI transport) for endpoint tests; override dependencies (app.dependency_overrides) to inject test doubles for DB/auth.UploadFile with size limits, content-type validation, and streaming to storage — never buffer multi-GB uploads in memory.time.sleep in async def endpoints; profile under load to catch it.get_db without try/finally close exhausts the connection pool under traffic./docs and /openapi.json are great in dev; restrict or disable them on public deployments if they reveal internals.allow_origins=["*"] with credentials; be explicit about origins in production.response_model_exclude_unset — PATCH endpoints overwriting fields with defaults; use exclude_unset for partial updates.httpx without timeouts hanging workers; set timeouts on every external call.TestClient hiding async bugs — portal-based TestClient can mask event-loop issues; test async paths with a real ASGI transport too.response_model nesting — deeply nested response models with N+1-prone computed fields; profile serialization on list endpoints.dependencies=[...] on routers — auth applied per-endpoint instead of once on the router; include shared deps at include_router time.还没有评价。欢迎分享你的使用感受。
无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。
还没有评论。来写第一条吧。
Master 1Password: vaults, Watchtower, passkeys, SSH agent, CLI, and family/team administration. Use when getting full value from 1Password personally or administering it for others.
中文简介正在准备中。当前显示原文说明。
Create 3D visuals with modeling, texturing, lighting, rendering, and optimization for web and product.
中文简介正在准备中。当前显示原文说明。
Create 3D web experiences: scene setup, models, materials, lighting, animation, scroll-driven scenes, and performance budgets. Use when adding 3D to websites beyond basic demos.
中文简介正在准备中。当前显示原文说明。
Writing abstracts that get papers read — structured content, the 5-sentence core, and journal-specific constraints.
中文简介正在准备中。当前显示原文说明。
Learn effectively from courses and academies: choosing programs, studying actively, and converting courses into skills. Use when investing time/money in structured learning.
中文简介正在准备中。当前显示原文说明。
Audit designs for accessibility with WCAG checklists covering color, type, focus, motion, and content.
中文简介正在准备中。当前显示原文说明。