agent-instructions
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what does not, structure, and…
Use when building APIs with FastAPI. Covers dependency injection, Pydantic v2 validation, async database access, authentication, background tasks, and testing.
$ npx -y skills add nimadorostkar/Claude-Skills-collection --skill fastapi --agent claude-codeHow it fires
How this skill gets triggered: by you, by Claude, or both.
/fastapiContext preview
The summary Claude sees to decide when to auto-load this skill.
Use when building APIs with FastAPI. Covers dependency injection, Pydantic v2 validation, async database access, authentication, background tasks, and testing.
name: fastapi description: Use when building APIs with FastAPI. Covers dependency injection, Pydantic v2 validation, async database access, authentication, background tasks, and testing. metadata: category: backend version: 1.0.0 tags: [fastapi, python, pydantic, async, api]
Build FastAPI services that use the framework's strengths — declarative validation and dependency injection — without falling into its two standard traps: blocking calls inside `async def`, and business logic in the route handler.
1. **Define the schemas** — Separate request, response, and internal models. Never return an ORM object directly; a `response_model` is your defense against leaking a password hash. 2. **Build the dependencies** — Database session, current user, feature flags. These are the injection points that make the app testable. 3. **Keep handlers thin** — Parse, authorize, delegate, return. Business logic lives in a service module that knows nothing about HTTP. 4. **Get async right** — In an `async def` handler, every I/O call must be awaited. A blocking call there stalls the entire event loop, not just that request. 5. **Test through the app** — `httpx.AsyncClient` with `app.dependency_overrides` gives you real routing, real validation, and a fake database.
**Dependency-injected handler and an overridable test:**
from typing import Annotated
from fastapi import APIRouter, Depends, HTTPException, status
router = APIRouter(prefix="/orders", tags=["orders"])
SessionDep = Annotated[AsyncSession, Depends(get_session)]
CurrentUser = Annotated[User, Depends(get_current_user)]
@router.post("", response_model=OrderRead, status_code=status.HTTP_201_CREATED)
async def create_order(
payload: OrderCreate,
session: SessionDep,
user: CurrentUser,
) -> Order:
try:
return await orders.place(session, customer_id=user.id, items=payload.items)
except InsufficientInventory as e:
raise HTTPException(status.HTTP_409_CONFLICT, detail=str(e)) from e@pytest.fixture
async def client(session: AsyncSession) -> AsyncIterator[AsyncClient]:
app.dependency_overrides[get_session] = lambda: session
app.dependency_overrides[get_current_user] = lambda: User(id="usr_test")
transport = ASGITransport(app=app)
async with AsyncClient(transport=transport, base_url="http://test") as c:
yield c
app.dependency_overrides.clear()A curated library of 137 production-grade skills for Claude and other AI coding agents. Every skill follows one structure, speaks with one voice, and earns its place by changing what the agent does.
Repo: nimadorostkar/Claude-Skills-collection
Use when writing project instructions for a coding agent (CLAUDE.md, AGENTS.md, or equivalent). Covers what belongs in them, what does not, structure, and…
Use when an agent needs state that survives a session or a context compaction. Covers what to persist, file-based memory, structuring notes for retrieval, and…
Use when automating agent behavior with lifecycle hooks. Covers hook events, deterministic enforcement of rules the model should not be trusted to remember,…
Use when packaging skills, commands, hooks, and MCP servers into a distributable plugin. Covers manifest structure, bundling, versioning, testing, and…
Use when writing a new skill for an AI agent. Covers scoping, description writing for reliable triggering, progressive disclosure, and the difference between a…
Use when reviewing or improving an existing agent skill. Covers triggering accuracy, content quality, redundancy with the base model, and measuring whether the…