python cursorrules prompt file best practices
via PatrickJS/awesome-cursorrules
Python development best practices with typing, testing, and modern tooling standards.
What is python cursorrules prompt file best practices?
Establishes conventions for Python projects emphasizing modular structure, comprehensive testing with pytest, type annotations, and CI/CD integration. Use this rule to maintain consistency across Python codebases and ensure AI-assisted development follows professional standards.
- Enforces type annotations and explicit return types on all functions and classes
- Requires PEP 257 docstring conventions for functions, classes, and modules
- Mandates pytest-based testing with full type annotations and docstrings in ./tests directory
- Standardizes project structure with separate directories for source, tests, docs, and config
- Integrates modern tooling: uv for dependency management, Ruff for code style, GitHub Actions/GitLab CI for automation
- Implements robust error handling, logging with context capture, and environment variable configuration management
Applies to
File patterns this rule matches.
Rule definition (reference)
Source of truth, from the repository.
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
Related rules
Python development guidance with CLI and file system expertise
Django development best practices guide for scalable, maintainable web applications.
FastAPI development with async-first patterns, Pydantic validation, and scalable architecture.
FastAPI best practices, project structure, and development patterns for Python async web APIs.
Expert guidance for building scalable FastAPI APIs with React and TypeScript frontends.
Flask development guide with custom Drawscape Factorio module integration for JSON-based entity processing.
