
Claude Code with Python: CLAUDE.md patterns that keep it in your conventions
Python has enough ways to do things that Claude will make choices based on what's most common in its training data, not what's right for your project. Old-style string formatting, different testing frameworks, varying import styles, type annotation inconsistency — all of these create drift. Here's the CLAUDE.md setup that keeps Python projects consistent. Core CLAUDE.md for a Python project # Python project rules ## Environment - Python 3.11+ - Virtual environment: .venv/ (do not reference system Python) - Package manager: uv (not pip, not poetry) - Run commands: uv run python, uv run pytest ## Code style - Type annotations on all functions (parameters and return type) - No untyped function signatures - f-strings for string formatting (not .format() or %) - dataclasses or Pydantic models for structured data (not plain dicts) - Named arguments for any function call with more than 2 arguments ## Project structure - Source code: src/[package_name]/ - Tests: tests/ (mirrors src/ structure)
Continue reading on Dev.to Python
Opens in a new tab




