Skip to content
This repository was archived by the owner on Sep 3, 2026. It is now read-only.

Repository files navigation

Pro Python Universal Agentic AI Skill 🐍✨

skills.sh Python Version License: Apache 2.0 Compatible Agents

The definitive universal agent skill distilling Marty Alchin's classic "Pro Python" (Apress), fully modernized for Python 3.10–3.13+. Equips AI coding assistants with deep object model reasoning, advanced OOP patterns, C3 linearization, and declarative framework architecture.


⚑ Instant Install via skills.sh / npx skills

Install this skill instantly into any agentic coding harness (Claude Code, Cursor, Windsurf, Gemini CLI, PicoClaw, Nanobot, Hermes, OpenClaw, OpenHands, Roo Code, Goose, etc.):

# πŸš€ Universal 1-command install (interactive)
npx skills add psthi/pro-python-skill

# 🌐 Install globally across all current and future workspaces
npx skills add psthi/pro-python-skill -g

# 🎯 Install specifically for a target agent (e.g. Claude Code)
npx skills add psthi/pro-python-skill -g --agent claude-code

# πŸ“‹ Preview available skills without installing
npx skills add psthi/pro-python-skill --list

πŸ“‘ Table of Contents


🌟 Executive Overview

While most developer AI prompts rely on generic syntax rules, pro-python embeds the foundational mental models and architectural design patterns that separate amateur scripts from professional Python frameworks.

Synthesized from Marty Alchin's Pro Python and bridged with modern Python 3.10–3.13+ language primitives (PEPs 487, 544, 557, 593, 612, 634, 654), this skill provides:

  1. Deterministic OOP Decisions: When to use Metaclasses vs __init_subclass__, how MRO resolves in multiple inheritance, and how to write cooperative super() chains.
  2. Negative Constraints & Anti-Patterns: "Tells & Smells" rules that stop LLMs from introducing subtle bugs (e.g. keying caches on instances inside decorator closures, bare except:, or omitting functools.wraps).
  3. Declarative Framework Engineering: Architectural runbook for designing ORMs, schema validators, and data pipelines.

πŸ†š Why This Skill?

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Typical LLM Behavior          β”‚ Behavior with Pro Python Skill                              β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ Uses fragile `isinstance`     β”‚ Employs `typing.Protocol` + duck typing for loose coupling  β”‚
β”‚ Writes monolithic `if/elif`   β”‚ Uses Structural Pattern Matching (`match / case`)           β”‚
β”‚ Leaks memory in closures      β”‚ Implements thread-safe `@functools.cached_property`         β”‚
β”‚ Breaks cooperative MRO chains β”‚ Enforces C3-linearized cooperative `super()` calls          β”‚
β”‚ Guesses text encodings        β”‚ Enforces strict `bytes` vs UTF-8 `str` transport discipline β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quickstart for Novices

1. Install to Local Agents

npx skills add psthi/pro-python-skill -g

Or clone and run the local multi-agent installer:

git clone https://github.com/psthi/pro-python-skill.git
cd pro-python-skill
bash scripts/install.sh

2. How to Prompt Your AI Agent

Once installed, your agents will automatically reference these frameworks whenever designing Python architectures. You can also query specific chapters or patterns explicitly:

  • "Using the pro-python skill, design a plugin system for our data loaders using __init_subclass__."
  • "Check our class hierarchy against the C3 MRO linearization rules in ch04."
  • "Refactor this decorator using ParamSpec to preserve type hints as described in ch12."

πŸ’» Deep Dive for Advanced Developers

1. C3 Linearization & Cooperative super()

Python flattens multiple-inheritance graphs using the C3 linearization algorithm. super() does not call the literal immediate parent in source code; it resolves dynamically against the runtime instance's MRO:

class Base:
    def action(self):
        print("Base.action")

class MixinA(Base):
    def action(self):
        print("MixinA start")
        super().action()

class MixinB(Base):
    def action(self):
        print("MixinB start")
        super().action()

class Combined(MixinA, MixinB):
    def action(self):
        super().action()

# MRO: Combined -> MixinA -> MixinB -> Base -> object
# Calling Combined().action() correctly chains through both mixins!

2. Class Customization: __init_subclass__ vs Metaclasses

  • Use __init_subclass__ (PEP 487) for zero-metaclass subclass registries without metaclass conflict issues:
class Exporter:
    registry = {}
    @classmethod
    def __init_subclass__(cls, format_name=None, **kwargs):
        super().__init_subclass__(**kwargs)
        if format_name:
            cls.registry[format_name] = cls

class HTMLExporter(Exporter, format_name="html"): pass
  • Reserve Metaclasses (type.__new__ / __prepare__) for inspecting/altering the class namespace dictionary before class instantiation occurs.

3. Type-Preserving Decorators with ParamSpec

Never lose argument types or autocomplete when wrapping functions:

from functools import wraps
from typing import Callable, ParamSpec, TypeVar

P = ParamSpec("P")
R = TypeVar("R")

def retry(func: Callable[P, R]) -> Callable[P, R]:
    @wraps(func)
    def wrapper(*args: P.args, **kwargs: P.kwargs) -> R:
        return func(*args, **kwargs)
    return wrapper

4. Structural Subtyping with typing.Protocol

Define explicit interface contracts decoupled from class inheritance:

from typing import Protocol, runtime_checkable

@runtime_checkable
class Serializer(Protocol):
    def serialize(self) -> dict[str, str]: ...

πŸ“š Chapter & Reference Index (12 Chapters)

# Chapter Key Frameworks
1 ch01: Principles & Philosophy Zen of Python, Samurai Principle, DRY, Pareto & Robustness Rules
2 ch02: Advanced Basics try/except/else/finally, Exception Chaining, Context Managers (with), Generators
3 ch03: Functions & Decorators *args/**kwargs, Closures, Optional-Argument Decorator Pattern, Partial Application
4 ch04: Classes & Metaclasses Inheritance, C3 Linearization, Cooperative super(), Metaclasses, __prepare__()
5 ch05: Common Protocols Operator Overloading, Comparison Protocols (__eq__ + __ne__), Iterables
6 ch06: Object Management Identity/Type/Value, Borg Pattern, Reference Counting, GC, Caching Descriptors
7 ch07: Strings & Encodings bytes vs str, struct Binary Packing, Unicode Encodings, UTF-8
8 ch08: Documentation Naming discipline, Docstring standards, reStructuredText, Sphinx
9 ch09: Testing doctest vs unittest.TestCase, Assertion specificity (assertEqual vs assertTrue)
10 ch10: Distribution & Packaging Licensing (MIT/BSD/LGPL/GPL), Packaging history, PyPI standards
11 ch11: Sheets CSV Framework Capstone Declarative Framework, Metaclass field registration, Instantiation ordering
12 ch12: Modern Python Bridge __init_subclass__, typing.Protocol, @functools.cached_property, ParamSpec, @dataclass(slots=True), match/case, pyproject.toml

πŸ§ͺ Executable Code Examples

Located in examples/:


πŸ“„ Contributing & License

  • Skill Wrapper License: Apache-2.0
  • Source Attribution: Based on "Pro Python" by Marty Alchin (Apress, 2010), synthesized and modernized for Python 3.10–3.13+ coding agents.
  • Framework & Tooling Credit: Structured and generated using the book-to-skill framework by @virgiliojr94.

About

Universal AI Agent Skill distilling Marty Alchin's 'Pro Python' (Apress), modernized for Python 3.10-3.13+ (Metaclasses, __init_subclass__, Descriptors, MRO, typing.Protocol, ParamSpec)

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages