fastapi
БесплатноБез исполняемых скриптовНе проверенUse when building, reviewing, testing, securing or shipping a FastAPI / async Python service — routers, Pydantic v2 schemas, dependency injection, async…
от lza6★ 19 звёзд на GitHubОб этом скилле
FastAPI & modern Python services
The single authoritative skill for building, reviewing, testing, securing and shipping an async FastAPI service on Python 3.12+. The mental model: the app is a thin async HTTP layer over typed dependencies, a service/repository core, and explicit DB sessions. Routes validate and delegate; they never own business logic, raw SQL, or secrets.
Pinned stack: Python 3.12+, FastAPI 0.136+, Starlette 1.0+ (FastAPI 0.136 requires it;
avoid <1.0.1, GHSA-86qp-5c8j-p5mr), Pydantic v2 (2.7+) + pydantic-settings 2.x,
SQLAlchemy 2.0 async, Alembic 1.13+, asyncpg 0.30 / psycopg 3, httpx 0.28+,
pytest 8 + pytest-asyncio 1.0+ (asyncio_mode=auto), ruff 0.7+, mypy 1.13+ strict,
uv 0.5+, uvicorn 0.32+ / gunicorn 23+ + uvicorn-worker 0.3+, PyJWT 2.10+, argon2-cffi 23+,
pip-audit 2.7+, PostgreSQL 16. (All lower bounds; install the latest in each line.)
⚠️ SDD new-feature gate — read this first. If this skill fired on a new, non-trivial feature or behaviour change and there is no approved spec + plan under
02-DOCS/wiki/sdd/, STOP — do not write feature code yet. Hand off to../specify/SKILL.mdfirst: it runs brainstorm → spec → plan → tasks before any code, then routes back here once the plan is approved. Build here directly only for a genuinely one-line / low-risk change. Method:../sdd/SKILL.md.
Out of scope, and where it goes instead: django for Django; Flask / sync WSGI,
notebooks and CLI-only scripts (no skill); language-level Python, typing and packaging →
python; framework-agnostic REST contracts — status codes, URL naming, versioning,
cursor vs offset → api-design (this skill covers their FastAPI implementation);
engine-level schema, indexing, EXPLAIN, zero-downtime migrations, PgBouncer →
postgresdb; language-agnostic injection / secret / authz theory →
secure-coding; Dockerfile, Compose and CI/CD mechanics →
deployment (this skill keeps only a Docker note).
Decision rules
async deffor any I/O route + async drivers (asyncpg, httpx); neverrequests/psycopg2/blocking calls on the loop (offload viaawait anyio.to_thread.run_sync).- Three Pydantic models per resource —
XCreate/XUpdate/XResponse(from_attributes=True); responses never leak hashes/tokens/internal flags. - Request-scoped resources via
Annotated[T, Depends(...)], never built inline — so tests can override them. - One DB session per request via
get_db(commit-on-success / rollback-on-exception); handlers never commit. - One error envelope
{"error":{"code","message","details?"}}via centralized handlers; never leak stack traces / SQL. - Settings from
pydantic-settings(BaseSettings), never scatteredos.getenv. - Validate JWT
exp/iss/audand pinalgorithms=["RS256"|"HS256"]explicitly. - Tests:
ASGITransport+dependency_overrideson a transactional DB; CI gates onruff,mypy --strict,pytest --cov,pip-audit.
Project layout
app/
├── main.py # create_app() factory + lifespan; app = create_app()
├── core/
│ ├── config.py # Settings(BaseSettings) + get_settings()
│ ├── security.py # hashing, JWT encode/decode
│ └── logging.py # structlog / JSON logging setup
├── api/
│ ├── deps.py # get_db, get_current_user, Pagination, require_roles
│ └── routers/
│ ├── users.py
│ └── health.py
├── schemas/ # Pydantic v2 models (Create/Update/Response)
│ └── user.py
├── models/ # SQLAlchemy 2.0 DeclarativeBase models
│ └── user.py
├── db/
│ ├── base.py # engine, async_sessionmaker, Base
│ └── repository.py # generic async Repository[ModelT]
├── services/ # business logic (no FastAPI imports)
│ └── user_service.py
├── exceptions.py # AppError hierarchy + register_exception_handlers
tests/ # pytest-asyncio + ASGITransport
alembic/ # async env.py + versions/
pyproject.toml # ruff + mypy strict + pytest config
Routers stay thin, services hold the logic, the repository/CRUD layer owns persistence.
Application factory + lifespan
from contextlib import asynccontextmanager
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.routers import health, users
from app.core.config import Settings, get_settings
from app.db.base import engine
from app.exceptions import register_exception_handlers
# Routers paired with their mount prefix + OpenAPI tag, declared once so the factory
# stays a flat loop instead of a wall of include_router() calls.
ROUTERS = (
(health.router, "/health", "health"),
(users.router, "/api/v1/users", "users"),
)
@asynccontextmanager
async def lifespan(_app: FastAPI):
# Open pools/caches on startup (here), never at import time, so importing the module has
Установить fastapi в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл fastapi?
Use when building, reviewing, testing, securing or shipping a FastAPI / async Python service — routers, Pydantic v2 schemas, dependency injection, async SQLAlchemy 2.0, OAuth2/JWT, ASGITransport tests, production wiring. NOT language-level Python or packaging (that is `python`), NOT engine-level SQL (that is `postgresdb`), NOT framework-agnostic REST contracts (that is `api-design`).
Как установить скилл fastapi?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл fastapi запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic