20 python rules available
Cursor has 20 Python rules, spanning FastAPI, Django, pandas, pytest, async and language features such as descriptors, metaclasses and match statements. Half are under 250 characters. The file below is the baseline every Python change should satisfy; pair it with the framework-specific rule you use.
Cursor applies project rules stored as .mdc files in .cursor/rules. Each rule's frontmatter (description, globs, alwaysApply) decides whether it is always included, attached to matching files, chosen by the agent from its description, or only used when you @-mention it. Cursor also reads AGENTS.md in the project root and subdirectories for plain-Markdown instructions.
.cursor/rules/python.mdcStarting point, not a tested configuration for your repository. Attached when files matching the globs are in context (alwaysApply: false with globs). Review the instructions, adapt the file paths and run your project's existing checks.
--- description: "Python development project conventions" globs: "**/*.py" alwaysApply: false --- # Python instructions for Cursor ## Focus for this project - Use dataclasses or Pydantic models for structured data instead of dicts with string keys. - Use match statements only when requires-python is 3.10 or later. - Add dependencies with the project's manager (uv, Poetry or pip-tools) and commit the lockfile change. ## Python conventions - Read requires-python in pyproject.toml first. Use built-in generics such as list[str] (3.9+) and X | None unions (3.10+) only when the minimum version allows them at runtime. - Annotate public functions and keep Any out of new signatures. - Raise specific exception types and never use a bare except:. - Use the formatter, linter and type checker already configured in pyproject.toml instead of introducing new ones. ## Before you finish - Run the configured linter and type checker (for example ruff check . and mypy) and pytest -q and report the actual output. If you cannot run them, say so and list the exact commands instead of saying they pass. - Summarize which of the rules above affected the change. - If another attached Cursor rule conflicts with this one, name both rules and follow the one with the narrower globs.
Create your own Cursor rules for Python and share with the community.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Cursor's docs recommend keeping individual rules under 500 lines and splitting large rules into composable ones. Cursor's documentation states that it supports AGENTS.md in the project root and in subdirectories. Use AGENTS.md for plain-Markdown instructions you also want other tools to read, and .mdc rules when you need Cursor's scoping options (globs, description-based selection, always-apply).
Documentation checked 2026-11-05: Cursor docs: Rules
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
You use Cursor's agent across a FastAPI service and data scripts and want consistent typing, tooling and tests regardless of which specialized rule is attached.
Add a function that groups invoices by customer and returns totals as typed records.
A dataclass or Pydantic model for the result, a typed function valid for requires-python, pytest cases for empty and multi-customer input, and lint/type/test output.
Content reviewed 2026-11-05. Confirm instruction activation in your installed client before relying on it.
Cursor rule for pandas code with method chains, vectorised ops, explicit date parsing, nullable dtypes, observed groupby and pandas 3 Copy-on-Write habits.