faif/python-patterns is a server-side project on GitHub with 43.1k stars, written primarily in Python. A collection of design patterns/idioms in Python
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
A collection of design patterns and idioms in Python.
Remember that each pattern has its own trade-offs. And you need to pay attention more to why you're choosing a certain pattern than to how to implement it.
Creational Patterns
Patterns that deal with object creation — abstracting and controlling how instances are made.
graph LR
Client -->|requests object| AbstractFactory
AbstractFactory -->|delegates to| ConcreteFactory
ConcreteFactory -->|produces| Product
Builder -->|step-by-step| Director
Director -->|returns| BuiltObject
FactoryMethod -->|subclass decides| ConcreteProduct
Pool -->|reuses| PooledInstance
Pattern
Description
abstract_factory
use a generic function with specific factories
borg
a singleton with shared-state among instances
builder
instead of using multiple constructors, builder object receives parameters and returns constructed objects
factory
delegate a specialized function/method to create instances
lazy_evaluation
lazily-evaluated property pattern in Python
pool
preinstantiate and maintain a group of instances of the same type
prototype
use a factory and clones of a prototype for new instances (if instantiation is expensive)
Structural Patterns
Patterns that define how classes and objects are composed to form larger, flexible structures.
Better alternatives: use module-level variables or dependency injection.
🌀 God Object
Why not:
Centralizes too much logic in a single class.
Makes code harder to test and maintain.
Better alternative: split functionality into smaller, cohesive classes.
🔁 Inheritance overuse
Why not:
Deep inheritance trees make code brittle.
Prefer composition and delegation.
“Favor composition over inheritance.”
Videos
Design Patterns in Python by Peter Ullrich
Sebastian Buczyński - Why you don't need design patterns in Python?
You Don't Need That!
Pluggable Libs Through Design Patterns
Contributing
When an implementation is added or modified, please review the following guidelines:
Docstrings
Add module level description in form of a docstring with links to corresponding references or other useful information.
Add "Examples in Python ecosystem" section if you know some. It shows how patterns could be applied to real-world problems.
facade.py has a good example of detailed description, but sometimes the shorter one as in template.py would suffice.
Python 2 compatibility
To see Python 2 compatible versions of some patterns please check-out the legacy tag.
Update README
When everything else is done - update corresponding part of README.
Travis CI
Please run the following before submitting a patch:
If you have a bash-compatible shell, use ./lint.sh to run formatting,
linting, type checking, and tests.
Development dependencies are pinned in Pipfile.lock. After changing
Pipfile, activate a Python 3.10 virtual environment and run make lock to
regenerate it.
Contributing via issue triage
You can triage issues and pull requests on CodeTriage.
No homepage URL was recorded for faif/python-patterns in TopGit's last sync. The README tab above frequently contains screenshots and demo links, or check the repository description on GitHub.
How active is development on faif/python-patterns?
The most recent commit recorded on faif/python-patterns was 14 days ago, based on the GitHub push timestamp. The repository has 7.0k forks — one of the better signals of community interest.
Is faif/python-patterns open source?
TopGit's metadata for faif/python-patterns does not record a license. Most public repositories on GitHub ARE open source, but the exact terms vary — verify by opening the LICENSE file directly.
What topics is faif/python-patterns associated with?
GitHub's repository topics for faif/python-patterns: "design-patterns", "idioms", "python". TopGit's editorial category is Backend.
Where do I read more about faif/python-patterns?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/faif/python-patterns is the definitive source.
Read full README in the tab above.
Is python-patterns worth your time?
ChatGPT, Claude and Perplexity can all read this page. Ask one of them what it makes of python-patterns.