fastapi
Skill33 starsChanged 22 days agoMITView on GitHub
Use when building APIs with FastAPI. Covers dependency injection, Pydantic v2 validation, async database access, authentication, background tasks, and testing. Trigger on "fastapi endpoint is slow under load", "set up depends for the db session", "pydantic v2 validation error", "test my fastapi app". Do not use for API contract decisions like pagination or versioning — see the api-design skill.
We split this skill into the rules it gives an agent
2 rules. 0 are common, 0 are distinctive, and 2 are very specific to this project.
0
Common
Most of the 25 edited versions we read keep these.
0
Distinctive
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 54
Always set response_model.
- Very specific: line 55
Use Annotated[Session, Depends(get_session)] — it keeps signatures readable and reusable.
“Common” is measured: kept by at least 6 in 10 of the 25 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
Purpose
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.
When to Use
- Building or reviewing a FastAPI application.
- Structuring dependencies, authentication, and database sessions.
- Diagnosing latency that appears only under concurrency.
- Writing tests for FastAPI endpoints.
Capabilities
- Route and router organization.
- Pydantic v2 models for request, response, and settings.
- Dependency injection with scoped lifecycles.
- Async SQLAlchemy sessions, correctly scoped per request.
- Authentication and authorization dependencies.
- Testing with
httpx.AsyncClientand dependency overrides.
Inputs
- The API contract and the data layer.
- Whether the workload is I/O-bound (nearly always) or CPU-bound.
Outputs
- Thin route handlers delegating to service functions.
- Response models that control exactly what is serialized.
- A test suite that overrides dependencies rather than mocking internals.
Workflow
- Define the schemas — Separate request, response, and internal models. Never return an ORM object directly; a
response_modelis your defense against leaking a password hash. - Build the dependencies — Database session, current user, feature flags. These are the injection points that make the app testable.
- Keep handlers thin — Parse, authorize, delegate, return. Business logic lives in a service module that knows nothing about HTTP.
- Get async right — In an
async defhandler, every I/O call must be awaited. A blocking call there stalls the entire event loop, not just that request. - Test through the app —
httpx.AsyncClientwithapp.dependency_overridesgives you real routing, real validation, and a fake database.
Best Practices
- A blocking call inside
async def(a sync DB driver,requests,time.sleep) blocks every concurrent request on that worker. If a handler must call blocking code, define it asdef— FastAPI runs it in a thread pool. - Always set
response_model. Without it, whatever your service returns is what the client sees, including fields you added last week. - Use
Annotated[Session, Depends(get_session)]— it keeps signatures readable and reusable. - Validate settings with
pydantic-settingsat startup. Fail to boot on a bad config rather than at 3am on the first request that touches it. BackgroundTasksruns in the same process and dies with it. For anything that must not be lost, use a real queue.- Mount routers by domain, not by HTTP verb.
Examples
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()Notes
- Pydantic v2 is roughly an order of magnitude faster than v1 on validation, but
Configclasses, validators, and.dict()all changed. Do not mix idioms. @lru_cacheon a settings factory is the standard way to make configuration a singleton dependency.- FastAPI's generated OpenAPI schema is only as good as your response models and status codes. Treat the generated docs as a review artifact.
Other versions27 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 27
- kid-sid/claude-spellbook★ 190same name
- youlaitech/youlai-skills★ 63same name
- Bbar0n234/learnflow-ai★ 35same name
- G1Joshi/Agent-Skills★ 15same name
- harness-studio/harness-studio★ 9same name
- DongDuong2001/pudo-code-system★ 5same name
- jawwad-ali/claude-code-skills★ 4same name
- Spardutti/claude-skills★ 3same name
- ffsshhttiikk/opencode-agents-skills★ 2same name
- qyndex/claude-init★ 2same name
17 more not listed
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.
Used alongsideProjects with it also use docker, plan and 1 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.
wrsmith108Skilldocker
Container-based development for isolated, reproducible environments. Use when running npm commands, installing packages, executing code, or managing project dependencies. Trigger phrases include "npm install", "run the build", "start the server", "install package", or any code execution request.
Also in 4 projects that use this
BlockSkillplan
Draft a TDD, PRD, or lightweight plan in the conversation without committing it.
Also in 3 projects that use this
BlockSkillfrontend-design
Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
Also in 3 projects that use this
In this repository137 other files it gives its agents.
- agent-instructionsSkill
- agent-memorySkill
- hooksSkill
- plugin-developmentSkill
- skill-authoringSkill
- skill-reviewSkill
- slash-commandsSkill
- subagentsSkill
- agent-designSkill
- context-engineeringSkill
- fine-tuningSkill
- llm-cost-optimizationSkill
- llm-evaluationSkill
- llm-integrationSkill
- mcp-serverSkill
- ml-pipelineSkill
- model-selectionSkill
- prompt-engineeringSkill
- ragSkill
- structured-outputSkill
- api-designSkill
- background-jobsSkill
- cachingSkill
- djangoSkill
- event-driven-architectureSkill
- graphqlSkill
- microservicesSkill
- nestjsSkill
- realtime-websocketsSkill
- spring-bootSkill
- competitive-analysisSkill
- lead-researchSkill
- product-analysisSkill
- resumeSkill
- user-researchSkill
- database-performanceSkill
- data-modelingSkill
- data-qualitySkill
- pandasSkill
- postgresSkill
- sparkSkill
- brand-guidelinesSkill
- generative-artSkill
- themingSkill
- ui-reviewSkill
- visual-designSkill
- architecture-decisionsSkill
- bug-fix-protocolSkill
- cli-developmentSkill
- code-reviewSkill
- debuggingSkill
- design-patternsSkill
- domain-modelingSkill
- git-workflowSkill
- legacy-modernizationSkill
- refactoringSkill
- repository-explorationSkill
- simple-designSkill
- system-designSkill
- aws-cdkSkill
- The first 60 shown.
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.

