python-312-fastapi-best-practices-cursorrules-prom — Cursor rule
Guides Cursor to build FastAPI backends using Python 3.12, Poetry, and SQLAlchemy. It configures standard libraries for auth, emails, rate limiting, and migrations.
.cursor/rules/python-312-fastapi-best-practices-cursorrules-prom.mdcWhat python-312-fastapi-best-practices-cursorrules-prom does
This rule sets standard conventions for Python 3.12 backends powered by FastAPI. It pins dependency management to Poetry and database migrations to Alembic alongside SQLAlchemy and Pydantic. Instead of letting the AI pick arbitrary third-party packages, it prescribes fastapi-users, fastapi-jwt-auth, fastapi-mail, fastapi-cache, fastapi-limiter, and fastapi-pagination.
The rule also enforces clean code standards. These include PEP 8 compliance, explicit type hints, docstrings, unit tests, and list comprehensions. If your project relies on a different package manager instead of Poetry or custom token handling instead of fastapi-jwt-auth, this rule will conflict with your setup until edited.
What it helps with
- enforce Python 3.12 conventions and PEP 8 formatting in Cursor
- scaffold database migrations using Alembic and SQLAlchemy
- implement authentication with
fastapi-usersandfastapi-jwt-auth - apply rate limiting and caching to FastAPI route handlers
Example prompts for the agent
- Create a new protected FastAPI route with rate limiting and pagination.
- Generate a SQLAlchemy model for user profiles and create an Alembic migration.
- Set up an email dispatch function using fastapi-mail.
How to install python-312-fastapi-best-practices-cursorrules-prom
Manually: put the files in place
.cursor/rules/python-312-fastapi-best-practices-cursorrules-prom.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.claude/rules/python-312-fastapi-best-practices-cursorrules-prom.mdThe paths frontmatter field limits the files: move globs from the source into paths
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.github/instructions/python-312-fastapi-best-practices-cursorrules-prom.instructions.mdThe applyTo field sets which files it applies to: move globs from the source into applyTo
Manually: put the files in place
.devin/rules/python-312-fastapi-best-practices-cursorrules-prom.mdManually: put the files in place
.clinerules/python-312-fastapi-best-practices-cursorrules-prom.mdStep by step, with commands for each platform: Cursor rules: .mdc files, four modes and what replaced .cursorrules
Questions about python-312-fastapi-best-practices-cursorrules-prom
How to install python-312-fastapi-best-practices-cursorrules-prom in Cursor?
Create the file .cursor/rules/python-312-fastapi-best-practices-cursorrules-prom.mdc in your project root and paste the rule contents into it.
What frameworks and libraries does this rule require?
It requires Python 3.12, FastAPI, Pydantic, SQLAlchemy, Alembic, and Poetry. It also specifies extensions like fastapi-users, fastapi-jwt-auth, and fastapi-pagination.
Does this rule apply to every file automatically?
No, because alwaysApply is set to false. Cursor loads it dynamically when the context matches the **/* pattern.
Source text
python-312-fastapi-best-practices-cursorrules-prom.mdc · CC0-1.0
--- description: "Cursor rules for Python FastAPI development with best practices." globs: **/* alwaysApply: false --- 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 1. **Use Meaningful Names**: Choose descriptive variable, function, and class names. 2. **Follow PEP 8**: Adhere to the Python Enhancement Proposal 8 style guide for formatting. 3. **Use Docstrings**: Document functions and classes with docstrings to explain their purpose. 4. **Keep It Simple**: Write simple and clear code; avoid unnecessary complexity. 5. **Use List Comprehensions**: Prefer list comprehensions for creating lists over traditional loops when appropriate. 6. **Handle Exceptions**: Use try-except blocks to handle exceptions gracefully. 7. **Use Virtual Environments**: Isolate project dependencies using virtual environments (e.g., `venv`). 8. **Write Tests**: Implement unit tests to ensure code reliability. 9. **Use Type Hints**: Utilize type hints for better code clarity and type checking. 10. **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.
© PatrickJS · CC0-1.0 · PatrickJS/awesome-cursorrules