fastapi

Builds and reviews Python HTTP APIs with FastAPI, Pydantic v2, and async request handling.

22|Updated Sep 10, 2026
One-click install
npx skills add https://github.com/Lynricsy/HyperSkills --skill fastapi-lynricsy
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastapi
Source: https://github.com/Lynricsy/HyperSkills/tree/main/skills/fastapi
Command: npx skills add https://github.com/Lynricsy/HyperSkills --skill fastapi-lynricsy

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? FastAPI codebases accumulate subtle defects that pass review and fail in production: blocking calls inside async handlers that stall every request, response models that silently drop subclass fields or leak secrets, tests that patch dependencies without effect, and lifespan state that never initializes under a bare TestClient. This Skill encodes the verified rules, workflows, and edge cases for building and reviewing FastAPI services correctly against FastAPI 0.141, Pydantic 2.13, and Starlette 1.6. ## Core Features & Use Cases - 25 core rules with enforcement gates: Annotated dependency declarations, async def versus def selection, the 40-slot threadpool limit, structural secret filtering, Starlette-level exception handlers, and the FAST ruff lint group. - Four guided workflows: add-or-change-an-endpoint, fix-a-slow-or-stalling-endpoint, write-or-fix-tests, and migrate-legacy-fastapi-code, each ending in a verifiable gate. - Seven in-depth references: dependency injection, Pydantic models at the HTTP boundary, responses and error contracts, async and lifecycle, streaming and SSE, testing with dependency_overrides and ASGITransport, and project tooling. - Use Case: A reports API degrades from 40ms to 9 seconds under load and loses background jobs on redeploy. The Skill identifies blocking calls inside async handlers, moves multi-minute work from BackgroundTasks to a queue with a 202 job id, and replaces deprecated on_event hooks with a lifespan context manager. ## Quick Start Ask the agent to review your FastAPI router or endpoint file for correctness, performance, and testing issues using the fastapi skill.

Frequently Asked Questions about fastapi

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I fix a slow FastAPI endpoint under load?

Check async def handlers for blocking calls like requests, time.sleep, or synchronous database drivers, which stall the entire event loop. Either declare the handler as def so FastAPI runs it in the threadpool, or wrap the blocking call with run_in_threadpool or asyncer.asyncify.

How do I override FastAPI dependencies in tests?

Set app.dependency_overrides[get_current_user] = fake before creating the test client, and clear overrides in teardown. Patching the module attribute with monkeypatch does not work because the route captured the callable when the decorator ran.

Should I use async def or def for FastAPI path operations?

The handler body decides: use async def only when every call is awaited, and def when the body contains any blocking call, which FastAPI runs in the threadpool. A single blocking call inside async def stalls every in-flight request on that worker.

Why does TestClient not run my FastAPI lifespan code?

A bare TestClient(app) never runs lifespan, so startup state is missing and failures surface as unrelated AttributeError exceptions. Use the context manager form with TestClient(app) as client, preferably inside a pytest fixture.

How do I prevent FastAPI responses from leaking sensitive fields?

Define a separate public response model that never declares fields like password_hash, rather than relying on response_model_exclude lists. A model that does not declare the field cannot leak it, while exclusion lists are forgotten on new endpoints.

When should I use BackgroundTasks versus a task queue in FastAPI?

BackgroundTasks runs in the same worker process after the response with no retry or persistence, so it suits sub-second work whose loss is acceptable. For anything that must not be lost, return 202 with a job id and hand the work to a real queue like Celery, arq, or Dramatiq.