python fastapi
via PatrickJS/awesome-cursorrules
FastAPI best practices, async patterns, and Pydantic validation for Python web APIs
What is python fastapi?
Provides guidance on building FastAPI applications with proper dependency injection, async/await patterns, and Pydantic schemas. Use this rule when developing REST APIs in FastAPI to ensure type safety, validation, and adherence to framework conventions.
- Use Pydantic models for request and response schemas with automatic validation
- Implement dependency injection for shared resources and cleaner code organization
- Utilize async/await for non-blocking operations and better performance
- Apply proper error handling with HTTPException and FastAPI's built-in error responses
- Leverage FastAPI's automatic OpenAPI documentation and JSON Schema generation
- Organize code with models, schemas, routers, dependencies, and services folders
Applies to
File patterns this rule matches.
Rule definition (reference)
Source of truth, from the repository.
Python FastAPI .cursorrules
FastAPI best practices
fastapi_best_practices = [ "Use Pydantic models for request and response schemas", "Implement dependency injection for shared resources", "Utilize async/await for non-blocking operations", "Use path operations decorators (@app.get, @app.post, etc.)", "Implement proper error handling with HTTPException", "Use FastAPI's built-in OpenAPI and JSON Schema support", ]
Folder structure
folder_structure = """ app/ main.py models/ schemas/ routers/ dependencies/ services/ tests/ """
Additional instructions
additional_instructions = """
- Use type hints for all function parameters and return values
- Implement proper input validation using Pydantic
- Use FastAPI's background tasks for long-running operations
- Implement proper CORS handling
- Use FastAPI's security utilities for authentication
- Follow PEP 8 style guide for Python code
- Implement comprehensive unit and integration tests """
Related rules
Senior full-stack TypeScript, React, Node.js guidance with clean architecture, testing, and WHY-oriented reasoning.
Quantitative factor research skills for designing, evaluating, and mining alpha factors in equities markets.
Android development with Jetpack Compose, clean architecture, and Material Design 3.
Angular development with Novo Elements UI library using standalone components.
Expert Angular 18 + TypeScript development with Jest, emphasizing clean code and performance.
Manage Kubernetes clusters, add-ons, stacks, and credentials via the Ankra CLI platform.