cursor / claude rules

CLAUDE.md for Python Projects

CLAUDE.md template for Claude Code in Python projects. Type hints, project structure, testing, and virtual environments.
by cache.directory updated May 18, 2026 CC-BY-4.0

## what it does

CLAUDE.md for Python

# Python Project

## Stack
- Python 3.12+
- Type hints REQUIRED on all functions
- uv for dependency management
- pytest for testing

## Commands
- `uv run pytest` — run tests
- `uv run ruff check .` — linting
- `uv run ruff format .` — formatting
- `uv run python -m myapp` — run application

## Conventions
- All functions MUST have type hints (params + return)
- Use `from __future__ import annotations` in every file
- Prefer dataclasses or Pydantic models over dicts
- Use pathlib.Path instead of os.path
- f-strings for string formatting (never .format())
- Use `if __name__ == "__main__":` guard in scripts

## Error Handling
- Custom exceptions in exceptions.py
- Never catch bare `except Exception`
- Use contextlib for resource management

## Testing
- Tests mirror src structure in tests/
- Use pytest fixtures, not setUp/tearDown
- Parametrize repetitive test cases
- Mock external services, not internal logic

## embed this badge

cache ✓ in cache.directory
![cached](https://cache.directory/badge/claude-md-python.svg)