c/backend › command
0votes

Cursor rules for Python projects

TemplateLow risk
submitted by u/client to c/backend · 0 copies

A .cursor/rules/python.mdc for typed, tested, well-structured Python.

Template · 3 variables
---
description: Python conventions
globs: ["**/*.py"]
alwaysApply: false
---

# Python

- Python {{python_version}}; type hints on every function signature; `mypy` clean.
- Format and lint with ruff (`ruff format`, `ruff check --fix`).
- Small pure functions; side effects (I/O, network, DB) at the edges.
- Use dataclasses or Pydantic models instead of loose dicts for structured data.
- Raise specific exceptions; never use bare `except:`.
- Tests with pytest in `tests/`, mirroring the package layout; use fixtures, not globals.
- Dependencies managed with {{dependency_tool}}; don't add packages without saying why.

## When you change code
- Follow the patterns in the nearest existing file before inventing new ones.
- Add or update a test for behavior changes; run `{{test_command}}`.
- Keep diffs small; explain anything surprising in your reply.
0 commentsreport

How to use this command

  1. Fill in the blanks. Type your details into the boxes above. This command has 3 blanks:
    • {{python_version}} Python version
    • {{dependency_tool}} Dependency tool
    • {{test_command}} Test command
  2. Copy itwith the Copy button. Your answers are filled in automatically. Use “copy raw” to keep the blanks for later.
  3. Paste it into Cursor, Claude, ChatGPT or Codex and send it.
  4. Tip: This produces a file or document. Save the filled-in result in your project (for example as CLAUDE.md or AGENTS.md) so you can reuse it.

More from c/backend

See all of c/backend →
0 comments

Log in to join the discussion.