python 312 fastapi best practices cursorrules prom
via PatrickJS/awesome-cursorrules
Python 3.12 FastAPI development with Pydantic, SQLAlchemy, and authentication best practices.
What is python 312 fastapi best practices cursorrules prom?
Enforces Python 3.12 FastAPI conventions using Poetry, Pydantic, SQLAlchemy, and specialized FastAPI extensions for auth, email, caching, and rate limiting. Follow this rule when building modern async APIs with structured dependency management and database migrations via Alembic.
- Enforce Python 3.12 syntax and FastAPI framework patterns with Pydantic models
- Require Poetry for dependency management and Alembic for database schema migrations
- Integrate fastapi-users, fastapi-jwt-auth, fastapi-mail, fastapi-cache, fastapi-limiter, and fastapi-pagination libraries
- Apply PEP 8 style, type hints, docstrings, and exception handling throughout
- Promote clean code practices: meaningful names, list comprehensions, virtual environments, and unit tests
Applies to
File patterns this rule matches.
Rule definition (reference)
Source of truth, from the repository.
Here are some best practices and rules you must follow:
- You use Python 3.12
- Frameworks:
- pydantic
- fastapi
- sqlalchemy
- You use poetry for dependency management
- You use alembic for database migrations
- You use fastapi-users for user management
- You use fastapi-jwt-auth for authentication
- You use fastapi-mail for email sending
- You use fastapi-cache for caching
- You use fastapi-limiter for rate limiting
- You use fastapi-pagination for pagination
- Use Meaningful Names: Choose descriptive variable, function, and class names.
- Follow PEP 8: Adhere to the Python Enhancement Proposal 8 style guide for formatting.
- Use Docstrings: Document functions and classes with docstrings to explain their purpose.
- Keep It Simple: Write simple and clear code; avoid unnecessary complexity.
- Use List Comprehensions: Prefer list comprehensions for creating lists over traditional loops when appropriate.
- Handle Exceptions: Use try-except blocks to handle exceptions gracefully.
- Use Virtual Environments: Isolate project dependencies using virtual environments (e.g.,
venv). - Write Tests: Implement unit tests to ensure code reliability.
- Use Type Hints: Utilize type hints for better code clarity and type checking.
- Avoid Global Variables: Limit the use of global variables to reduce side effects.
These rules will help you write clean, efficient, and maintainable Python code.
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.