About this project
python-patterns is a reference collection of design patterns and idioms implemented in Python. Rather than a library, it is a learning resource: each pattern lives in its own small module under a category folder, and the README indexes them with short descriptions.
Coverage is organized into several groups. Creational patterns include abstract_factory, borg, builder, factory, lazy_evaluation, pool and prototype. Structural patterns include 3-tier, adapter, bridge, composite, decorator, facade, flyweight, front_controller, mvc and proxy. Behavioral patterns include chain_of_responsibility, catalog, chaining_method, command, interpreter, iterator (with an alternative implementation), mediator, memento, observer, publish_subscribe, registry, servant, specification, state, strategy, template and visitor. There are also design-for-testability examples (dependency_injection with three variants), a fundamental delegation_pattern, and other patterns such as blackboard, graph_search and a hierarchical state machine (hsm).
The README explicitly frames patterns as trade-offs, encouraging readers to focus on why a pattern is chosen rather than only how it is coded. It also documents anti-patterns that are discouraged in Python, including singleton (modules are already singletons), god object, and overuse of inheritance, with suggested alternatives such as module-level variables, dependency injection, composition and delegation.
Each example module is expected to carry a module-level docstring with references and, where possible, an "Examples in Python ecosystem" section showing real-world usage. The project maintains a legacy tag for Python 2 compatible versions of some patterns. Contribution guidance covers docstrings, README updates, and running ./lint.sh for formatting, linting, type checking and tests; development dependencies are pinned in Pipfile.lock and regenerated with make lock. Issue triage is supported through CodeTriage, and the README links several conference talks and videos about design patterns in Python.
Comments
0 people shared their preference · Deer Point appears after 10 participants
Sign in to join the discussion.