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.

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)
├── 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.0.tar.gz (39.2 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.0-py3-none-any.whl (51.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: modern_python_guidance-0.1.0.tar.gz
  • Upload date:
  • Size: 39.2 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.0.tar.gz
Algorithm Hash digest
SHA256 e785aa6431da99865e2df5d00fed91917a256d5e0761f0abf62645dd0d93f69f
MD5 88737191f9d45733d142c4a177c7ceea
BLAKE2b-256 f72c0ec961fa73a2dc59ac8ac6e1d440fbedd65b71d2cabe73840b4f697f5117

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for modern_python_guidance-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9d27884797e7fa557616926cf2507b14dae165bd47c7f215a32b65237080770f
MD5 4feb1ac55efd25813de93a7b7545766f
BLAKE2b-256 c15071495bfba67f1adf7f5db0bd9bc34305ac736256e51adccbe134cb95e936

See more details on using hashes here.

Provenance

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