Cursor Rules for Python: .mdc Rule Set From Your Repo Facts
Ppromptstudio·Oct 15, 2026
No rating
Generate Cursor project rules for a Python repo: .mdc files with globs for source, tests, and migrations, built from your real tooling, layout, and commands.
Act as a Python tech lead who writes Cursor project rules for a team repo: short .mdc files in .cursor/rules/ that tell Cursor's Agent how this codebase is built, tested, and typed, using only facts from the repo.
Inputs:
- Python version, package manager, formatter, linter, and type checker as configured: [PythonToolchain]
- Top-level folders and what lives in each: [RepoLayout]
- Framework and the patterns the code follows (for example FastAPI routers, Django apps, plain scripts): [FrameworkPatterns]
- Test runner, test folder, fixtures, and how external services are faked: [TestSetup]
- Commands that exist in this repo, copied from the Makefile, pyproject scripts, or CI: [RealCommands]
- Things the Agent must never do here: [NeverDo]
- Mistakes the Agent has already made in this repo: [AgentMistakes]
Generate:
1. A file plan: each .mdc file name, its rule type (Always Apply, Apply to Specific Files, Apply Intelligently, or Apply Manually), and why.
2. python-core.mdc: frontmatter with globs for source files and alwaysApply false, then rules for typing, imports, error handling, logging, and style that match PythonToolchain (point to the formatter instead of restating style).
3. tests.mdc: globs for the test folder only; how to write and name tests, use fixtures, and fake services per TestSetup.
4. One more file for the riskiest area in RepoLayout (for example migrations or the API layer), with a description so the Agent can pull it in when relevant.
5. A short always-apply file with the RealCommands and the NeverDo list.
6. A check list: every command, path, and tool named in the rules, each traced to an input, so nothing was invented.
7. Two test prompts to paste into Agent to confirm the rules load and change its behavior.
Rules:
- Name only tools, paths, and commands that appear in the inputs.
- Keep each file under 60 lines; the whole set well under 500 lines.
- Each line in AgentMistakes becomes one direct rule.