fastapi

Write FastAPI code following current best practices for routing, dependencies, and streaming.

3|1|Updated Nov 30, 2025
One-click install
npx skills add https://github.com/PALabs-v1/AI_friend --skill fastapi-palabs-v1
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: fastapi
Source: https://github.com/PALabs-v1/AI_friend/tree/main/.claude/skills/fastapi
Command: npx skills add https://github.com/PALabs-v1/AI_friend --skill fastapi-palabs-v1

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? FastAPI evolves quickly, and outdated patterns like Ellipsis defaults, RootModel wrappers, and deprecated response classes lead to suboptimal code. This Skill keeps generated FastAPI code aligned with the latest conventions and features. ## Core Features & Use Cases - Modern API Patterns: Enforces Annotated-based parameters and dependencies, return-type-driven serialization, and router-level prefixes, tags, and shared dependencies. - Streaming Support: Provides patterns for Server-Sent Events with EventSourceResponse, JSON Lines, and byte streaming via StreamingResponse. - Frontend Serving: Uses app.frontend() and router.frontend() to serve built static apps from Vite, Astro, or similar tools. - Use Case: When building a new REST endpoint with authentication and a streamed response, the Skill produces code using Annotated dependencies, a declared return type, and EventSourceResponse instead of deprecated alternatives. ## Quick Start Ask the AI to create a FastAPI endpoint with dependency injection and SSE streaming following current best practices.

Frequently Asked Questions about fastapi

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

FAQPage Schema
How do I stream Server-Sent Events in FastAPI?

Use response_class=EventSourceResponse and yield items from the endpoint. Plain objects are JSON-serialized as data fields, while ServerSentEvent instances give full control over event, id, retry, and comment fields.

How do I use dependency injection in FastAPI?

Declare dependencies with Annotated types and Depends(), creating a reusable type alias for each dependency. Dependencies support yield for cleanup, scope settings of request or function, and router-level sharing via dependencies lists.

Should I use async or sync path operations in FastAPI?

Use async only when the called logic is fully async-compatible and non-blocking. By default use regular def functions, which run in a threadpool and avoid blocking the event loop.

Can FastAPI serve a frontend app built with Vite or Astro?

Yes, use app.frontend() or router.frontend() with the build directory. These are low-priority routes, so API routes match first and client-side routing fallbacks work for single-page apps.

Why should I avoid Pydantic RootModel in FastAPI?

FastAPI creates a TypeAdapter for plain annotated types like list[int] with Field constraints, so wrapper RootModels are unnecessary. Use Annotated with Body() and Field validators directly in the endpoint signature.