python fastapi
via PatrickJS/awesome-cursorrules
FastAPI best practices, project structure, and development patterns for Python async web APIs.
What is python fastapi?
Provides guidance on FastAPI conventions including Pydantic schemas, dependency injection, async patterns, error handling, and folder organization. Use this rule when building REST APIs with FastAPI to maintain consistent code structure and leverage the framework's built-in features effectively.
- Use Pydantic models for request/response validation and schema generation
- Implement dependency injection for shared resources and middleware
- Utilize async/await for non-blocking I/O operations
- Apply path operation decorators (@app.get, @app.post, etc.) for routing
- Handle errors with HTTPException and proper HTTP status codes
- Leverage FastAPI's automatic OpenAPI documentation and JSON Schema support
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
Expert guidance for building scalable FastAPI APIs with React and TypeScript frontends.
Flask development guide with custom Drawscape Factorio module integration for JSON-based entity processing.
Python development standards with GitHub integration, testing, and security best practices.
Python LLM & ML development guide with modern tooling, type safety, and workflow best practices.
Structured Python development guide emphasizing modular design, testing, and AI-friendly coding practices.
PyTorch and scikit-learn for chemistry ML with best practices for molecular data.
