Skip to main content

Version-aware BAD/GOOD pattern guides that help AI coding agents generate modern Python

Project description

modern-python-guidance

CI PyPI version Python License

LLMs often produce outdated Python — typing.List instead of list, @validator instead of @field_validator, setup.py instead of pyproject.toml. This tool provides 39 version-aware BAD/GOOD pattern guides that show the modern replacement, filtered by your project's Python version.

Note: The tool itself requires Python 3.11+ to run. Guides cover patterns from Python 3.9 onward, and --python-version filters guides for your target environment.

Quick start

# Install
pip install modern-python-guidance

# Search for a pattern
mpg search "pydantic validator"
#   pydantic-v2-validators                   score=18.0  [pydantic]

# Get the full guide
mpg retrieve pydantic-v2-validators
# --- pydantic-v2-validators (version match: YES) ---
# ## BAD
# @validator("name")
# ...
# ## GOOD
# @field_validator("name")
# ...

mpg is the short alias for modern-python-guidance. Both work.

CLI usage

# Search guides by keyword
mpg search "pydantic validator"

# Retrieve a specific guide (full BAD/GOOD content)
mpg retrieve use-builtin-generics

# List all guides compatible with your Python version
mpg list --python-version 3.11

# Auto-detect project Python version from pyproject.toml / .python-version
mpg detect-version

# Filter by category
mpg search "timeout" --category async

# JSON output (default when piped, explicit with --format)
mpg search "typing" --format json | jq '.[0].id'

Guide coverage

39 guides across 3 layers:

Layer Categories Count Examples
1 — stdlib typing, async, stdlib, data-structures 16 list over List, match/case, TaskGroup
2 — frameworks pydantic, fastapi, httpx, django, sqlalchemy, pytest 18 Pydantic V2 migration, SQLAlchemy 2.0 style, Annotated[Depends]
3 — toolchain toolchain 5 uv over pip, ruff over flake8, pickle avoidance

Run mpg list to see all 39 guides, or browse them on GitHub.

Version-aware filtering

Guides specify their minimum Python version. The CLI auto-detects your project's version from (in order):

  1. --python-version flag
  2. pyproject.toml requires-python
  3. .python-version file
  4. Default: 3.11
# Only shows guides compatible with Python 3.9
mpg list --python-version 3.9
# Excludes: TaskGroup (3.11+), match/case (3.10+), etc.

MCP server

mpg includes a built-in MCP server that exposes all 4 commands as tools. AI agents (Claude Code, Cursor, Gemini CLI, etc.) can discover and call them directly.

Setup with Claude Code

claude mcp add mpg -- mpg mcp

Or add to .mcp.json manually:

{
  "mcpServers": {
    "mpg": {
      "command": "mpg",
      "args": ["mcp"]
    }
  }
}

Available tools

Tool Description
search_guides Search guides by keyword with fuzzy matching
retrieve_guides Get full BAD/GOOD content by guide ID
list_guides Browse all guides, filter by category/version
detect_python_version Auto-detect project Python version

The MCP server uses stdio transport (JSON-RPC 2.0) and adds zero additional dependencies.

Agent Skills integration

This project doubles as a Claude Code Agent Skills plugin. Install it into your project's .claude/skills/ to give Claude automatic access to modern Python patterns when writing or reviewing code.

# Find where the package is installed
SKILL_DIR=$(python -c "from pathlib import Path; import modern_python_guidance; print(Path(modern_python_guidance.__file__).parent / 'skills' / 'modern-python-guidance')")

# Symlink into your project
ln -s "$SKILL_DIR" your-project/.claude/skills/modern-python-guidance

For other AI tools (Cursor, Copilot, etc.), use the CLI directly — pipe mpg search or mpg retrieve output into your workflow.

Development

git clone https://github.com/yottayoshida/modern-python-guidance.git
cd modern-python-guidance
uv venv && source .venv/bin/activate
uv pip install -e ".[dev]"
pytest
ruff check src/ tests/

Project structure

src/modern_python_guidance/
├── cli.py              # Entry point (search, retrieve, list, detect-version, mcp)
├── mcp_server.py       # MCP server (JSON-RPC 2.0 over stdio)
├── frontmatter.py      # YAML-subset parser (no PyYAML dependency)
├── guide_index.py      # Guide discovery and indexing
├── search.py           # Weighted keyword search + fuzzy fallback
├── retrieve.py         # Guide retrieval and JSON rendering
├── version_detect.py   # Python version auto-detection
└── compat.py           # Shared helpers

skills/modern-python-guidance/
├── SKILL.md            # Agent Skills plugin entry point
└── guides/             # 39 guide files by category

See docs/design.md for the full design document.

Contributing

Contributions welcome! To add a new guide:

  1. Create skills/modern-python-guidance/guides/<category>/<id>.md
  2. Include YAML frontmatter with these fields:
Field Type Values
id string Unique kebab-case identifier (must match filename)
title string Short descriptive title
category string Must match parent directory name
layer int 1 (stdlib), 2 (frameworks), 3 (toolchain)
tags list Search keywords
aliases list Alternate names (old API names, etc.)
python string Minimum version, e.g. ">=3.11"
frequency string high (LLMs do this often), medium, low
  1. Write BAD/GOOD/Why/Version Notes sections
  2. Run pytest to verify the guide parses correctly

License

Apache-2.0 OR MIT — see LICENSE and LICENSE-MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

modern_python_guidance-0.2.0.tar.gz (69.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

modern_python_guidance-0.2.0-py3-none-any.whl (65.9 kB view details)

Uploaded Python 3

File details

Details for the file modern_python_guidance-0.2.0.tar.gz.

File metadata

  • Download URL: modern_python_guidance-0.2.0.tar.gz
  • Upload date:
  • Size: 69.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for modern_python_guidance-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f75c1267e4f6a26f8628fc4e1b68c3a6cd72b92487dbe84675035d44646f4d80
MD5 7eb6f796d0333dc99f8ef6f9ad66c75c
BLAKE2b-256 53d85aeb9ac69fde6e7879b43807a27204c251d02fad5bb3893a9d9df34778d3

See more details on using hashes here.

Provenance

The following attestation bundles were made for modern_python_guidance-0.2.0.tar.gz:

Publisher: publish.yml on yottayoshida/modern-python-guidance

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file modern_python_guidance-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for modern_python_guidance-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72e968819a86bda2399ac50971bd59981cda7344e32fed380cfd374794f41695
MD5 7fe72239800e6d850b2e80dacaad6f3b
BLAKE2b-256 e3f77ddc3bc7ce1a6aa2dea206f2cbbea48bcbaa5cd6dabf26c7edcd27dd9260

See more details on using hashes here.

Provenance

The following attestation bundles were made for modern_python_guidance-0.2.0-py3-none-any.whl:

Publisher: publish.yml on yottayoshida/modern-python-guidance

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page