Skip to main content
rule

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.

Install into Cursor · Manually: put the files in place All methods and platforms ↓
.cursor/rules/python-312-fastapi-best-practices-cursorrules-prom.mdc
Open on GitHub

What 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-users and fastapi-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.mdc

Frontmatter: description, globs, alwaysApply

Step 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

Similar IDE rules

All IDE rules for Backend and APIs →

From the same set210

python-fastapi-best-practices-cursorrules-prompt-f A Cursor rule that sets the agent's coding style for Python and FastAPI: functional code, Pydantic v2, async operations. ★ 41,024repo stars python-django-best-practices-cursorrules-prompt-fi Directs Cursor to generate idiomatic Django code with clean MVT architecture and optimized ORM queries. ★ 41,024repo stars python-developer-cursorrules-prompt-file This rule gives Cursor a Python-focused development context for debugging, command-line work, and file operations. Use it for Python project tasks. ★ 41,024repo stars python-cursorrules-prompt-file-best-practices A Cursor rule that makes the assistant write Python with type annotations, PEP 257 docstrings and pytest tests. ★ 41,024repo stars python--typescript-guide-cursorrules-prompt-file This rule guides Cursor on Python and TypeScript work with Django, React, Tailwind, and InertiaJS. It fits projects that need readable code and explicit file references. ★ 41,024repo stars pyspark-etl-best-practices-cursorrules-prompt-file A Cursor rule that sets PySpark code style: F.col(), explicit joins, select over withColumn, and Iceberg-aware ETL structure. ★ 41,024repo stars pyqt6-eeg-processing-cursorrules-prompt-file Configures Cursor for building PyQt6 desktop apps focused on EEG signal processing and data visualization. Helps separate heavy analysis from the interface. ★ 41,024repo stars py-fast-api A Cursor rule for Python FastAPI backends. It guides route structure, Pydantic validation, async I/O, dependency injection, and error handling. ★ 41,024repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor