fastapi-expert
Skill5 starsChanged 3 months agoMITView on GitHub
Use when building or debugging FastAPI services - files importing fastapi, pydantic, or sqlalchemy.ext.asyncio; projects with pyproject.toml using uv/ruff/mypy; mentions of FastAPI, Pydantic v2, APIRouter, Depends, async endpoints, OAuth2/JWT auth, or pytest with httpx. Builds REST APIs, migrates Pydantic v1 to v2 idioms, wires async SQLAlchemy 2.0, adds auth and settings, writes async tests. Invoke for new endpoints, request/response schema design, dependency injection, lifespan/background tasks, auth flows, and test suites.
9 other projects use a version of this.
Adopted by
Most recently taken up by
- IAbuElRuzz/AgentSkillstheir own version, first seen Sep 16, 2026
- peakdong68/my-skillstheir own version, first seen Aug 29, 2026
- Leo-Atienza/atlas-claudetheir own version, first seen Jul 24, 2026
- james-paul25/claude-skilltheir own version, first seen Jul 11, 2026
- codeApe-7/ai-agent-workflowGrouptheir own version, first seen Jun 6, 2026
- SKB3002/agenthubtheir own version, first seen Apr 20, 2026
Used with
Projects with it also use postgres-pro, secure-code-guardian and 7 more.
Other files people use alongside this one.
Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
JeffallanSkillpostgres-pro
Use when optimizing PostgreSQL queries, configuring replication, or implementing advanced database features. Invoke for EXPLAIN analysis, JSONB operations, extension usage, VACUUM tuning, performance monitoring.
Also in 5 projects that use this
JeffallanSkillsecure-code-guardian
Use when implementing authentication/authorization, securing user input, or preventing OWASP Top 10 vulnerabilities — including custom security implementations such as hashing passwords with bcrypt/argon2, sanitizing SQL queries with parameterized statements, configuring CORS/CSP headers, validating input with Zod, and setting up JWT tokens. Invoke for authentication, authorization, input validation, encryption, OWASP Top 10 prevention, secure session management, and security hardening. For pre-built OAuth/SSO integrations or standalone security audits, consider a more specialized skill.
Also in 4 projects that use this
- +7 more from Jeffallan
Other versions9 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 9
- Jeffallan/claude-skills★ 12ksame name
- martinholovsky/claude-skills-generator★ 47same name
- codeApe-7/ai-agent-workflowGroup★ 17same name
- Leo-Atienza/atlas-claude★ 4same name
- SKB3002/agenthub★ 4same name
- IAbuElRuzz/AgentSkills★ 1same name
- james-paul25/claude-skill★ 0same name
- peakdong68/my-skills★ 0same name
- usmanmubarak1/ClaudeSkilledAgents★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository15 other files it gives its agents.
- docker-expertSkill
- engineering-rulesSkill
- fastify-expertSkill
- flutter-expertSkill
- go-expertSkill
- jetpack-compose-expertSkill
- mobile-qa-expertSkill
- nestjs-expertSkill
- playwright-expertSkill
- react-expertSkill
- react-native-expertSkill
- remix-expertSkill
- swiftui-expertSkill
- terraform-expertSkill
- vue-expertSkill
The file
We split this skill into the rules it gives an agent
7 rules. 0 are common, 1 is distinctive, and 6 are very specific to this project.
0
Common
Most of the 9 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
6
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 22
Add authentication (OAuth2 password flow + JWT) and per-route authorization
- Very specific: line 24
Write async test suites with httpx AsyncClient and dependency overrides
- Very specific: line 30
Implement: - write endpoints with Annotated dependencies, Pydantic v2 schemas (separate Create/Update/Read models), and async def only …
- Very specific: line 31
Verify lint/format: - run uv run ruff check . && uv run ruff format --check ..
- Very specific: line 32
Verify types: - run uv run mypy .; fix all reported issues and re-run until clean.
- Very specific: line 33
Test: - write or update pytest tests using httpx AsyncClient with ASGITransport and app.dependency_overrides for DB/auth (see …
- Very specific: line 34
Prove it works: - start the app (uv run uvicorn app.main:app --reload or uv run fastapi dev), hit the changed endpoints with curl …
“Common” is measured: kept by at least 6 in 10 of the 9 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
FastAPI Expert
Turns Claude into a senior Python backend engineer who ships FastAPI 0.115+ services with Pydantic v2 idioms, async SQLAlchemy 2.0, and a uv/ruff/mypy toolchain.
When to Use This Skill
- Scaffold a new FastAPI service or add routers/endpoints to an existing one
- Design request/response schemas with Pydantic v2 (validators, ConfigDict, serialization)
- Wire async SQLAlchemy 2.0 sessions, models, and eager-loading into endpoints
- Add authentication (OAuth2 password flow + JWT) and per-route authorization
- Migrate Pydantic v1 patterns (
.dict(),@validator,class Config) to v2 - Write async test suites with httpx
AsyncClientand dependency overrides - Configure settings, lifespan startup/shutdown, and background work
Core Workflow
- Analyze - read
pyproject.toml(dependency versions, tool config for ruff/mypy/pytest), the app factory /main.py, existing routers, and the session/settings modules. Match the project's layout (routers vs. flat, repository layer vs. inline queries) before writing anything. Confirm Pydantic is v2 and SQLAlchemy is 2.0 async - never mix v1 idioms in. - Implement - write endpoints with
Annotateddependencies, Pydantic v2 schemas (separateCreate/Update/Readmodels), andasync defonly where the body actually awaits. Register new routers on the app. Prefer editing existing modules over new files. - Verify lint/format - run
uv run ruff check . && uv run ruff format --check .; fix all reported issues and re-run until clean. - Verify types - run
uv run mypy .; fix all reported issues and re-run until clean. Do not silence errors with blanket# type: ignore- fix the types. - Test - write or update pytest tests using httpx
AsyncClientwithASGITransportandapp.dependency_overridesfor DB/auth (seereferences/testing.md). Runuv run pytest -q; fix every failure and re-run until all tests pass. - Prove it works - start the app (
uv run uvicorn app.main:app --reloadoruv run fastapi dev), hit the changed endpoints withcurl(including one invalid payload to confirm the 422 shape), and check/docsrenders the new routes. Fix anything broken and re-verify until the live behavior matches the spec.
Reference Guide
Load detailed guidance only when the task needs it:
| Topic | Reference | Load When |
| Pydantic v2 schemas, validators, serialization | references/pydantic-v2.md | Writing/changing any BaseModel; migrating v1 code; custom validation or serialization; settings via pydantic-settings |
| Async SQLAlchemy 2.0 engine, sessions, queries | references/async-sqlalchemy.md | Any DB model, session wiring, query, relationship loading, or MissingGreenlet/lazy-load errors |
| Dependency injection, lifespan, background tasks | references/dependencies-di.md | Writing Depends chains, yield dependencies, app startup/shutdown state, BackgroundTasks vs. task queue decisions |
| OAuth2 password flow + JWT auth | references/auth.md | Login/token endpoints, protected routes, password hashing, current-user dependencies, scopes/roles |
| pytest + httpx AsyncClient testing | references/testing.md | Writing or fixing tests, dependency overrides, test DB fixtures, async test config |
Key Patterns
Pydantic v2 schema trio with ORM reads (never .from_orm() / class Config):
from pydantic import BaseModel, ConfigDict, EmailStr
class UserCreate(BaseModel):
email: EmailStr
password: str
class UserRead(BaseModel):
model_config = ConfigDict(from_attributes=True)
id: int
email: EmailStr
user = UserRead.model_validate(db_user) # not User.from_orm(db_user)
payload = user.model_dump(mode="json") # not user.dict()Annotated dependencies, aliased once, reused everywhere:
from typing import Annotated
from fastapi import Depends
from sqlalchemy.ext.asyncio import AsyncSession
async def get_db() -> AsyncIterator[AsyncSession]:
async with async_session_factory() as session:
yield session
DbDep = Annotated[AsyncSession, Depends(get_db)]
CurrentUser = Annotated[User, Depends(get_current_user)]
@router.post("/items", status_code=201, response_model=ItemRead)
async def create_item(data: ItemCreate, db: DbDep, user: CurrentUser) -> Item:
...Lifespan context instead of deprecated @app.on_event:
from contextlib import asynccontextmanager
@asynccontextmanager
async def lifespan(app: FastAPI):
app.state.engine = create_async_engine(settings.database_url)
yield
await app.state.engine.dispose()
app = FastAPI(lifespan=lifespan)Async query with eager loading (no lazy loads after await):
from sqlalchemy import select
from sqlalchemy.orm import selectinload
result = await db.execute(
select(Order).options(selectinload(Order.items)).where(Order.user_id == user.id)
)
orders = result.scalars().all()Common Mistakes
- Pydantic v1 idioms in v2 code -
.dict(),.json(),parse_obj(),from_orm(),@validator,class Config,update_forward_refs(). Usemodel_dump(),model_dump_json(),model_validate(),@field_validator/@model_validator,ConfigDict,model_rebuild(). Mixing generations breaks silently or at import time. - Blocking calls inside
async defendpoints - sync DB drivers,requests,time.sleepblock the event loop for every request. Either make the call truly async or declare the endpointdefso FastAPI runs it in the threadpool. - Lazy-loading relationships after the session context - async SQLAlchemy raises
MissingGreenleton implicit IO. Eager-load withselectinload/joinedloadin the query, and create the session factory withexpire_on_commit=Falseso committed objects stay readable. - One global session or
Depends(get_db)at import time - sessions must be per-request via a yield dependency; a shared session breaks under concurrency and leaks transactions. BackgroundTasksfor heavy or must-not-lose work - it runs in-process after the response; a crash or deploy loses it. Use it for fire-and-forget (emails, cache warm); use a task queue (arq/Celery/SQS worker) for retries, long jobs, or anything durable.- Auth details wrong - storing plain or fast-hashed passwords (use bcrypt/argon2 via passlib or pwdlib), putting sensitive data in JWT claims, no
expcheck, or returning 403 instead of 401 withWWW-Authenticate: Beareron missing credentials. - Tests using
TestClientfor an async app with overrides left dirty - use httpxAsyncClient(transport=ASGITransport(app=app)), setapp.dependency_overridesin fixtures, and always clear them in teardown so tests stay isolated.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

