IDE-Tools · Foto: Homedust, CC BY 2.0
Python Cursorrules Prompt File Best Practices
Zuletzt aktualisiert:
Typ
Regel
Lizenz
CC0 1.0
Anwendungsfeld
Cursor Rules
Voraussetzungen
Keine besonderen — direkt loslegen.
Anleitung, wie man eigene .cursorrules-Dateien für Python-Projekte gut strukturiert.
Original-Beschreibung der Autoren: Cursor rules for Python development with best practices integration.
Die Regel
---
description: "Cursor rules for Python development with best practices integration."
globs: **/*
alwaysApply: false
---
You are an AI assistant specialized in Python development. Your approach emphasizes:
- Clear project structure with separate directories for source code, tests, docs, and config.
- Modular design with distinct files for models, services, controllers, and utilities.
- Configuration management using environment variables.
- Robust error handling and logging, including context capture.
- Comprehensive testing with pytest.
- Detailed documentation using docstrings and README files.
- Dependency management via https://github.com/astral-sh/uv and virtual environments.
- Code style consistency using Ruff.
- CI/CD implementation with GitHub Actions or GitLab CI.
AI-friendly coding practices:
- You provide code snippets and explanations tailored to these principles, optimizing for clarity and AI-assisted development.
Follow the following rules:
- For any Python file, ALWAYS add typing annotations to each function or class. Include explicit return types (including None where appropriate). Add descriptive docstrings to all Python functions and classes.
- Please follow PEP 257 docstring conventions. Update existing docstrings as needed.
- Make sure you keep any comments that exist in a file.
- When writing tests, ONLY use pytest or pytest plugins (not unittest). All tests should have typing annotations. Place all tests under ./tests. Create any necessary directories. If you create packages under ./tests or ./src/<package_name>, be sure to add an __init__.py if one does not exist.
All tests should be fully annotated and should contain docstrings. Be sure to import the following if TYPE_CHECKING:
from _pytest.capture import CaptureFixture
from _pytest.fixtures import FixtureRequest
from _pytest.logging import LogCaptureFixture
from _pytest.monkeypatch import MonkeyPatch
from pytest_mock.plugin import MockerFixture
So nutzt du sie
Die Regel kopieren (Button oben) oder als Datei herunterladen und im Projekt unter .cursor/rules/ ablegen — Cursor lädt sie beim nächsten Start automatisch. Ältere Cursor-Versionen lesen alternativ eine einzelne .cursorrules-Datei im Projektstamm; dort einfach den Regel-Text ohne den Kopfblock zwischen den ----Zeilen einfügen.
Der Regel-Text ist englisch — Cursor versteht ihn unabhängig von der Sprache, in der Sie mit dem Editor chatten.
Im Detail
Statt einer fertigen Coding-Regel liefert dieser Eintrag eine Anleitung eine Ebene höher: Wie strukturiert man eigene .cursorrules-Dateien so, dass Cursor sie zuverlässig befolgt, welche Abschnitte (Projektkontext, Konventionen, Beispiele, No-Gos) sinnvoll sind und wie man die Datei kurz genug hält, um im Kontextfenster zu bleiben. Der eigentliche Mehrwert liegt darin, projektspezifische Regeln selbst zu bauen statt nur fremde zu kopieren – gerade bei Teams mit eigenen, dokumentierten Konventionen zahlt sich das aus. Wer dagegen schnell eine fertige Regel für ein Standard-Framework wie FastAPI oder Django sucht, ist mit einer der konkreten Framework-Regeln direkt besser bedient als mit dieser Meta-Anleitung.
Praxis-Tipp
Als Vorlage nutzen: Abschnitt für Abschnitt mit den eigenen Team-Konventionen füllen, statt eine .cursorrules-Datei bei null zu beginnen.
Lizenz & Quelle
- Lizenz: CC0 1.0
- Quelle: PatrickJS/awesome-cursorrules (GitHub)
Inhalt ansehen (python-cursorrules-prompt-file-best-practices.mdc)
Lade …
Erfahrungen & Kommentare.
Funktioniert der Regel bei Ihnen? Tipps, Stolperfallen, Varianten — teilen Sie es mit der Community.
Lade Kommentare …
Passt dazu.
AI Agent Specialist
Cursor-Regel für diszipliniertes, klar abgegrenztes Agenten-Verhalten statt unstrukturierter KI-Antworten.
Alpha Skills Quant Factor Research
Cursor-Regel für methodisch saubere quantitative Faktor-Recherche im Trading-Umfeld.
Android Jetpack Compose
Cursor-Regel für idiomatischen, deklarativen Android-UI-Code mit Jetpack Compose.
