Skip to content
Cursor Rules Generator
Backend4 sections

Python Cursor Rules Template

Generate production-ready Python Cursor rules for Project Rules (.mdc), AGENTS.md, or legacy .cursorrules. This template encodes stack-specific conventions for projects using Python. High-level language with dynamic typing, extensive standard library, and broad ecosystem.

What This Template Covers

The template focuses Cursor AI on concrete Python practices instead of generic coding advice. Required sections are always included; optional sections can be enabled when they match your project.

Required guidance

  • - Code Style
  • - Type Hints
  • - Project Structure
  • - Error Handling

Default style

  • - Indentation: 4 spaces
  • - Quotes: double
  • - Semicolons: disabled
  • - Naming: snake_case

Example Python Rules

The generator turns these sections into Project Rules with frontmatter, AGENTS.md, or a single .cursorrules file depending on the output format you choose.

Code Style

- Follow PEP 8 conventions.
- Use 4 spaces for indentation (no tabs).
- Use {{QUOTE}} quotes for strings consistently.
- Maximum line length: 88 characters (Black default).
- Use snake_case for variables, functions, and methods.
- Use PascalCase for class names.

Type Hints

- Use type hints for all function signatures.
- Use Optional[T] instead of T | None for Python < 3.10 compatibility.
- Use collections.abc types for interfaces (Iterable, Sequence, Mapping).
- Use typing.TypedDict for structured dictionaries.
- Use dataclasses for data containers.
- Use Protocol for duck-typing interfaces.

Project Structure

- Use src-layout: put source code under src/ directory.
- Use pyproject.toml for project configuration.
- Separate tests in a tests/ directory mirroring the source tree.
- Use __init__.py files (even if empty) for explicit package boundaries.
- Use relative imports within packages where appropriate.
- Keep modules focused and under 500 lines.

Common Searches This Page Helps With

python cursor rulespython .cursorrulespython AGENTS.md

Frequently Asked Questions

What does the Python Cursor rules template include?
It includes 4 rule sections covering code style, type hints, project structure and other Python development conventions.
Can I generate Python Project Rules and AGENTS.md from the same template?
Yes. The generator can export the same stack-specific guidance as modern Project Rules (.mdc), AGENTS.md, or a legacy .cursorrules file.
Should I combine Python with other Cursor rules templates?
Yes. You can combine Python with related templates such as TypeScript, Tailwind CSS, Docker, or backend frameworks when your project uses multiple technologies.

Related Cursor Rules Templates