fastapi
Installation
Summary
FastAPI best practices and conventions for clean, modern API development.
- Use
Annotatedfor all parameter and dependency declarations to maintain type safety, reusability, and compatibility with other contexts - Declare return types or response models on path operations to enable automatic validation, filtering, serialization, and OpenAPI documentation
- Use
async defonly when calling async code withawait; default to regulardeffor blocking operations to avoid event loop blocking - Apply router-level configuration (prefix, tags, dependencies) on the
APIRouteritself rather than ininclude_router()calls - Avoid deprecated patterns like Ellipsis (
...) for required fields,RootModel, and custom JSON response classes; rely on Pydantic's Rust-based serialization for performance
SKILL.md
FastAPI
Official FastAPI skill to write code with best practices, keeping up to date with new versions and features.
Use the fastapi CLI
Run the development server on localhost with reload:
fastapi dev
Run the production server:
fastapi run