FastAPI best practices and conventions. Use when working with FastAPI APIs and Pydantic models for them. Keeps FastAPI code clean and up to date with the latest features and patterns, updated with new versions. Write new code or refactor and update old code.
The FastAPI skill provides developers with a set of best practices, patterns, and conventions for building APIs using FastAPI and Pydantic models. It addresses common challenges in maintaining clean, efficient, and up-to-date FastAPI code by guiding developers on modern, recommended approaches to parameter declarations, dependency injection, response modeling, and project structure. By standardizing these practices, the skill helps prevent anti-patterns and ensures that FastAPI applications remain maintainable, scalable, and compatible with the latest FastAPI versions and features.
Key features of this skill include a command-line interface (CLI) for running both development and production servers, integration with `pyproject.toml` for specifying app entrypoints, and support for using `Annotated` type hints in parameters and dependencies to improve code clarity and reusability. The skill also emphasizes avoiding outdated patterns, such as using `Ellipsis` for required fields, and encourages specifying return types or response models for API endpoints to enable validation, serialization, and documentation of responses. Additionally, it provides clear guidance for refactoring existing codebases to align with the latest best practices.
This skill is ideal for Python developers building web APIs with FastAPI, especially those aiming to maintain high code quality and modern standards. It is useful for teams working on new projects or maintaining and updating older FastAPI applications. Use cases include designing clean API endpoints, managing request and response validation with Pydantic, structuring project entrypoints, and ensuring dependency injection is reusable and type-safe. Overall, it supports both individual developers and teams seeking to adopt consistent, maintainable, and up-to-date FastAPI coding practices.
You can use the FastAPI CLI commands. Run `fastapi dev` for a development server with auto-reload or `fastapi run` for a production server. You can also specify a path to the app file if not using `pyproject.toml` entrypoints.
Yes, the skill recommends using `Annotated` for parameters such as `Path`, `Query`, `Header`, and for dependencies with `Depends()`. This approach ensures better type safety and reusability.
No, the skill advises against using Ellipsis. Required fields should be declared without `...`, as it is unnecessary and not recommended.
The skill focuses on best practices aligned with the latest FastAPI versions. While some practices may work with older versions, it is optimized for modern FastAPI features and patterns.
Yes, specifying return types or response models is recommended whenever possible. This allows FastAPI to validate, serialize, document, and filter API responses effectively.
Quick Setup:
.claude/skills/Repository
fastapi/fastapi