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

Stop your AI from writing typing.List, @validator, and setup.py. 41 version-aware BAD/GOOD pattern guides that teach AI coding agents to write modern Python — delivered via MCP, CLI, or Agent Skills.

Highlights

  • Measurable impact: AI writes modern Python 98% of the time with mpg, vs 79% without — even with vague prompts (Opus 4.8, V5 benchmark details)
  • 41 guides across stdlib, Pydantic, FastAPI, Django, SQLAlchemy, pytest, and toolchain
  • Version-aware: auto-detects your project's Python version and filters guides accordingly
  • 4 delivery methods: MCP server, CLI, Agent Skills, and Rules (auto-injects on .py file touch)
  • Not Ruff: Ruff auto-fixes syntax (Listlist). mpg guides design decisions that Ruff can't touch — TaskGroup over gather, Pydantic V2 migration, SQLAlchemy 2.0 style

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

Claude Code (recommended)

pip install modern-python-guidance
mpg setup

This registers the MCP server, links Agent Skills, and creates a Rules file (.claude/rules/modern-python.md) in one command. The Rules file auto-injects modern Python guidance whenever you touch Python-related files. Start a new Claude Code session afterwards — newly registered MCP servers, skills, and rules take effect on the next launch.

CLI

pip install modern-python-guidance
mpg search "pydantic validator"
mpg retrieve pydantic-v2-validators

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

Manual setup / other agents

MCP registration (Claude Code):

claude mcp add mpg -- mpg mcp

Other MCP-compatible agents (Cursor, Windsurf, etc.) — add to your MCP config:

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

Agent Skills + Rules only (Claude Code):

mpg setup --skills-only

mpg setup flags:

Flag Purpose
--mcp-only MCP registration only
--skills-only Project-local artifacts only (Skills + Rules)
--scope {user,local} MCP scope (default: user)
--project-dir PATH Target project for Skills/Rules symlinks
--dry-run Show what would be done

Uninstall — reverse mpg setup (deregister the MCP server and unlink Agent Skills + Rules):

mpg uninstall            # remove all
mpg uninstall --dry-run  # preview what would be removed
Flag Purpose
--mcp-only MCP deregistration only
--skills-only Project-local artifacts only (Skills + Rules)
--project-dir PATH Target project for Skills/Rules symlinks
--dry-run Show what would be done

mpg uninstall clears the MCP registration from every scope setup can write to (user and local), removes only the symlinks mpg created (never their targets or other files), and is idempotent — running it on an already-clean state is a harmless no-op.

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

# Scan a file for outdated patterns
mpg check app.py
mpg check app.py --format json | jq '.summary.guide_ids'
mpg check app.py --exit-zero  # always exit 0

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

Guide coverage

41 guides across 3 layers:

Layer Categories Count Examples
1 — stdlib typing, async, stdlib, data-structures 18 list over List, match/case, TaskGroup, deferred annotations, t-strings
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 41 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. pyproject.toml Poetry python constraint (^3.10, ~3.11, >=3.10,<3.14)
  4. .python-version file
  5. 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.

Recommended hooks

Add a PostToolUse hook to auto-check Python files whenever Claude edits them. Create or update .claude/settings.json in your project:

{
  "hooks": {
    "PostToolUse": [
      {
        "matcher": "tool == \"Edit\" || tool == \"Write\" || tool == \"MultiEdit\"",
        "hooks": [
          {
            "type": "command",
            "command": "mpg hook claude-post-tool-use"
          }
        ]
      }
    ]
  }
}

The hook reads stdin from Claude Code, checks any .py file for outdated patterns, and surfaces findings as inline feedback. Non-Python files and clean files produce no output.

Verify with /hooks in Claude Code to confirm the hook is active.

For manual CLI use, mpg check --quiet <file> provides the same check without the "no patterns found" message.

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

See CONTRIBUTING.md for project structure and guide authoring details.

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.5.3.tar.gz (155.3 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.5.3-py3-none-any.whl (82.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: modern_python_guidance-0.5.3.tar.gz
  • Upload date:
  • Size: 155.3 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.5.3.tar.gz
Algorithm Hash digest
SHA256 538adeb083f014c978c8719e8d853c867b1a613e2ff6d5b7bce486c7f26a5c31
MD5 909c0ddca658df60ff0aa402b92f2d16
BLAKE2b-256 69949d5948f49100e552f6e0ad8ea9cdd221adeaf97800c5e713f86e1010fee0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for modern_python_guidance-0.5.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7b76c8d9e47b6067d99d86781883958066884ded19c4601915715914cb22c5b4
MD5 f9bb0b7d0dd0644ad8adb26fd7c4a413
BLAKE2b-256 0c86aa518326b756b0fa45ad59b96bb38a9b865d7258268ed8769ccbc8145a82

See more details on using hashes here.

Provenance

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