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 30 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 "typing list"
#   use-builtin-generics                     score=18.0  [typing]

# Get the full guide
mpg retrieve use-builtin-generics
# --- use-builtin-generics (version match: YES) ---
# ## BAD
# from typing import List, Dict, Optional
# ...
# ## GOOD
# names: list[str] = []
# ...

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

30 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 9 Pydantic V2 migration, Annotated[Depends], AsyncClient
3 — toolchain toolchain 5 uv over pip, ruff over flake8, pickle avoidance

Run mpg list to see all 30 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/             # 30 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 — see LICENSE.

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.1.1.tar.gz (44.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.1.1-py3-none-any.whl (55.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: modern_python_guidance-0.1.1.tar.gz
  • Upload date:
  • Size: 44.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.1.1.tar.gz
Algorithm Hash digest
SHA256 f8f0e0645d4ceb321f22bff7908cea366a772fd334bd975a9ad2bc0c07dfddfe
MD5 c0d29f98acbf9d95a5cc97de6595dc5b
BLAKE2b-256 2f0298bcb5a7fc1277206eebf6adb98a0ec173acf68114054f1e6de996fa4314

See more details on using hashes here.

Provenance

The following attestation bundles were made for modern_python_guidance-0.1.1.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.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for modern_python_guidance-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 63c53cbd02914b709f2edfbe80af820e74e74f79461d025a5e6658d5856b71ee
MD5 e2eb4afd1f1cf2afec7581ec6ff1cd90
BLAKE2b-256 304957fe007518cad15d77c8e90ccfdfc0aff414898925b9606b8218c777bc09

See more details on using hashes here.

Provenance

The following attestation bundles were made for modern_python_guidance-0.1.1-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