FastAPI
Build fast, production-ready Python APIs with type hints, validation, and async support.
Popular
New
Join 2,279+ developers using this skill
skill
Build fast, production-ready Python APIs with type hints, validation, and async support.
Real data. Real impact.
Growing
Developers
Per week
Open source
Skills give you superpowers. Install in 30 seconds.
run_in_executortime.sleep() in async endpoints blocks everything — use await asyncio.sleep() insteadProcessPoolExecutor or background workersitems: list = [] shares the same list across requests — use Field(default_factory=list)Optional[str] doesn't make a field optional in the request — add = None or use Field(default=None)model_validate() not parse_obj(), and model_dump() not .dict() — v1 methods are deprecatedAnnotated[str, Field(min_length=1)] for reusable validated types instead of repeating constraintslru_cache on expensive dependencies or cache in app.state for singletonsDepends() without an argument reuses the type hint as the dependency — clean but can confuse readersyield dependencies for cleanup (DB sessions, file handles) — code after yield runs even if the endpoint raises@app.on_event("startup") is deprecated — use lifespan async context managerapp.state during lifespan, not as global variablesfrom contextlib import asynccontextmanager @asynccontextmanager async def lifespan(app): app.state.db = await create_pool() yield await app.state.db.close() app = FastAPI(lifespan=lifespan)
dict from endpoints, not Pydantic models directly — FastAPI handles serialization and it's fasterstatus_code=201 on POST endpoints returning created resources — 200 is the default but semantically wrongResponse with media_type="text/plain" for non-JSON responses — returning a string still gets JSON-encoded otherwiseresponse_model_exclude_unset=True to omit None fields from response — cleaner API outputraise HTTPException(status_code=404) — don't return Response objects for errors, it bypasses middleware@app.exception_handler(CustomError) — but remember they don't catch HTTPExceptiondetail= for user-facing messages, log the actual error separately — don't leak stack tracesBackgroundTasks runs after the response is sent but still in the same process — not suitable for long-running jobsOAuth2PasswordBearer is for documentation only — it doesn't validate tokens, you must implement that in the dependencyDepends(get_current_user) in path operation, not in router — dependencies on routers affect all routes including health checksTestClient runs sync even for async endpoints — use httpx.AsyncClient with ASGITransport for true async testingapp.dependency_overrides[get_db] = mock_db — cleaner than monkeypatchingTestClient context manager ensures lifespan runs — without with TestClient(app) as client: startup/shutdown hooks don't fireNo automatic installation available. Please visit the source repository for installation instructions.
View Installation Instructions1,500+ AI skills, agents & workflows. Install in 30 seconds. Part of the Torly.ai family.
© 2026 Torly.ai. All rights reserved.