Version-aware BAD/GOOD pattern guides that help AI coding agents generate modern Python
Project description
modern-python-guidance
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-versionfilters 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):
--python-versionflagpyproject.tomlrequires-python.python-versionfile- 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:
- Create
skills/modern-python-guidance/guides/<category>/<id>.md - 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 |
- Write BAD/GOOD/Why/Version Notes sections
- Run
pytestto verify the guide parses correctly
License
Apache-2.0 — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e785aa6431da99865e2df5d00fed91917a256d5e0761f0abf62645dd0d93f69f
|
|
| MD5 |
88737191f9d45733d142c4a177c7ceea
|
|
| BLAKE2b-256 |
f72c0ec961fa73a2dc59ac8ac6e1d440fbedd65b71d2cabe73840b4f697f5117
|
Provenance
The following attestation bundles were made for modern_python_guidance-0.1.0.tar.gz:
Publisher:
publish.yml on yottayoshida/modern-python-guidance
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modern_python_guidance-0.1.0.tar.gz -
Subject digest:
e785aa6431da99865e2df5d00fed91917a256d5e0761f0abf62645dd0d93f69f - Sigstore transparency entry: 1626400293
- Sigstore integration time:
-
Permalink:
yottayoshida/modern-python-guidance@040c5de80da93bbf7f3b8ef45b812ba78e38e7b9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/yottayoshida
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@040c5de80da93bbf7f3b8ef45b812ba78e38e7b9 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file modern_python_guidance-0.1.0-py3-none-any.whl.
File metadata
- Download URL: modern_python_guidance-0.1.0-py3-none-any.whl
- Upload date:
- Size: 51.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d27884797e7fa557616926cf2507b14dae165bd47c7f215a32b65237080770f
|
|
| MD5 |
4feb1ac55efd25813de93a7b7545766f
|
|
| BLAKE2b-256 |
c15071495bfba67f1adf7f5db0bd9bc34305ac736256e51adccbe134cb95e936
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
modern_python_guidance-0.1.0-py3-none-any.whl -
Subject digest:
9d27884797e7fa557616926cf2507b14dae165bd47c7f215a32b65237080770f - Sigstore transparency entry: 1626400336
- Sigstore integration time:
-
Permalink:
yottayoshida/modern-python-guidance@040c5de80da93bbf7f3b8ef45b812ba78e38e7b9 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/yottayoshida
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@040c5de80da93bbf7f3b8ef45b812ba78e38e7b9 -
Trigger Event:
workflow_dispatch
-
Statement type: