Command Palette

Search for a command to run...

Назад к скиллам
скилл № 38025

FastAPI

Builds, debugs, and hardens FastAPI services: async endpoints, Pydantic models, dependency injection, auth, and deployment. Use when writing or reviewing a…

БесплатноБез исполняемых скриптов
clawicот clawic★ 23 звезды на GitHub

Установить FastAPI в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Об этом скилле

User preferences live in ~/Clawic/data/fastapi/config.yaml (see Configuration); nothing else is stored on the user's machine. If you have data at an old location (~/fastapi/ or ~/clawic/fastapi/), move it to ~/Clawic/data/fastapi/, and say in one line that you moved it and from where.

When To Use

  • Writing or reviewing FastAPI code: routers, dependencies, request/response models, middleware
  • Diagnosing latency and stalls: one blocking call, an exhausted pool, a saturated threadpool
  • Modelling data at the edge: validation errors, serialization, ORM objects, pydantic v1 → v2
  • Wiring auth, settings, database sessions, and background work into the dependency graph
  • Getting a service to production: workers, proxies, shutdown, health checks, logging, limits
  • Fixing tests that pass wrongly, hang, or die with a closed event loop
  • Not for Django, Flask, or plain-Python problems — django, flask, py own those

Quick Reference

Situation Play
Every route got slow at once, health check included The loop is blocked: a sync call inside async def, or all threadpool slots busy → async.md
Choosing def vs async def for an endpoint Any blocking call in the body → def; all-await → async def → async.md
CPU work, image processing, big parsing in a request Off the loop and off the threadpool: process pool or queue → async.md
422 on a request that looks correct Read loc in the error body: alias, nesting, or a nullable field with no default → pydantic.md
.dict(), parse_obj, @validator, orm_mode no longer work Pydantic v2 renames and behavior changes → pydantic.md
ORM instance will not serialize into the response from_attributes plus a response model, or return the model you declared → pydantic.md
Depends runs more or fewer times than expected Per-request cache, use_cache=False, singletons in lifespan → dependencies.md
Current user, scopes, tokens, password hashing auth.md
/users/me hits the {user_id} route; 307 on POST; router prefixes Declaration order and trailing slashes → routing.md
Where files go, circular imports, app factory, one app or many structure.md
Env var ignored, secret in the wrong place, per-environment config settings.md
Sessions, pools, transactions, N+1, migrations, async ORM errors database.md
Error bodies inconsistent, custom handlers, validation error shape errors.md
CORS headers missing, middleware order, request IDs, body read twice middleware.md
Tests: dependency overrides, lifespan, async client, DB isolation testing.md
Workers, gunicorn vs uvicorn, root_path, graceful shutdown, containers deployment.md
Slow under load with the loop healthy: serialization, caching, pagination performance.md
Large uploads or downloads, SSE, streaming JSON, client disconnects streaming.md
WebSocket drops, broadcast across workers, authenticating a socket websockets.md
Work after the response: BackgroundTasks vs a real queue, retries background.md
Docs wrong or missing, generated clients, operation ids, examples openapi.md
Logs with no request context, health vs readiness, metrics, tracing observability.md
Ownership checks, mass assignment, SSRF, path traversal, security headers security.md
Server-rendered HTML: Jinja2, forms, HTMX partials, static files templates.md
Anything else Reproduce in one file: one route, no middleware, no DB — then add back one layer at a time until it breaks

Each file is one sub-job and self-contained: read SKILL.md by default, open exactly one guide when the situation matches.

Core Rules

  1. async def obliges the whole chain to await. One blocking call inside an async endpoint — psycopg2, requests, time.sleep, a large open().read() — freezes every concurrent request on that worker, not just its own. If any step blocks and cannot be replaced, declare the endpoint def and let Starlette move it to the threadpool.
  2. The threadpool has 40 slots per worker. Every def endpoint and def dependency shares AnyIO's default limiter of 40 threads: ceiling = 40 concurrent blocking calls per worker process, the 41st waits with no error message. Concurrency budget = 40 × workers; raise total_tokens in lifespan only after measuring.
  3. Dependencies cache per request, singletons live in lifespan. Depends(get_x) used in three places runs once per request and again on the next one. Anything that must exist once per process — DB engine, HTTP client, cache client — is created in the lifespan handler and stored on app.state; @lru_cache on a factory is the escape hatch for cheap, argument-free objects like settings.
  4. Validate at the edge, exactly twice. Request model in, response model out, plain objects in between. response_model re-validates everything you return, so a response is a seco
Полный SKILL.md на GitHub

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

  • _meta.json
  • async.md
  • auth.md
  • background.md
  • database.md
  • dependencies.md
  • deployment.md
  • errors.md
  • middleware.md
  • observability.md
  • openapi.md
  • performance.md
  • pydantic.md
  • routing.md
  • security.md
  • settings.md
  • streaming.md
  • structure.md
  • templates.md
  • testing.md
  • websockets.md

FAQ

Что делает скилл FastAPI?

Builds, debugs, and hardens FastAPI services: async endpoints, Pydantic models, dependency injection, auth, and deployment. Use when writing or reviewing a FastAPI app, router, or schema; when the API hangs or every route slows because a sync driver or CPU work blocks the event loop; when a request returns an unexpected 422, a POST becomes a 307, or a 500 arrives with no CORS headers; when migrating pydantic v1 to v2 (`model_dump`, `from_attributes`, `field_validator`); when `Depends` runs too often, `yield` cleanup misfires, or dependency overrides do not take; when SQLAlchemy raises `QueuePool limit` or `MissingGreenlet`, or connections leak across workers; when TestClient, httpx `AsyncClient`, or pytest-asyncio fail with a closed event loop; when uvicorn or gunicorn workers, graceful shutdown, `root_path`, or proxy headers need deciding; or when background tasks, WebSockets, SSE, uploads, or the OpenAPI docs misbehave. Not for Django, Flask, or general Python — `django`, `flask`, `py`.

Как установить скилл FastAPI?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл FastAPI запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить FastAPI с