A curated library of production-grade Python patterns — every one verified to actually run.
18 complete, self-contained implementations of the patterns that show up again and again in real distributed systems and infrastructure: rate limiters, circuit breakers, write-ahead logs, gossip protocols, two-phase commit, authorization engines, and more. No fluff, no half-finished snippets — each file executes, and every one is pure standard library.
How this was built (honest version): these patterns were generated with a local large language model (Qwen, running on my own hardware — no cloud API), then filtered hard: every file is executed by a run-gate, and only the ones that actually run — cleanly, on the standard library alone — make it in. The broken, the trivial, the truncated, and the dependency-heavy are cut. What's left is the signal. The curation is the work.
Most "code pattern" collections are either toy snippets or AI-generated walls of text that don't run. This one is the opposite: a small, ruthlessly filtered set where the only entry requirement is that it works. If a file is here, it passed execution — exit 0, real output, no traceback, no third-party imports.
- ✅ 18 complete systems, organized by domain
- ✅ 23 reusable components indexed (the substantial classes inside the systems)
- ✅ Verified — every file runs, and runs on the standard library alone (zero
pip install)
- ✅ MIT licensed — use them, ship them, no strings
Every pattern below is stdlib-only (Python 3.10+) and runs directly.
| Pattern |
What it does |
| metrics_exporter |
Metrics exporter (counters/gauges/histograms) |
| Pattern |
What it does |
| write_ahead_log |
Write-ahead log (WAL) for atomic transactions |
| Pattern |
What it does |
| lru_cache_ttl |
Thread-safe LRU cache with TTL expiration |
| Pattern |
What it does |
| atomic_file_write |
Atomic file write — write-then-rename, never a half-written file |
| safe_tree_walker |
Filtered directory walker — by size / extension / age |
| file_deduplicator |
Find (and optionally remove) duplicate files by content hash |
| folder_organizer |
Rule-based folder organizer — sort files by type / date |
| bulk_renamer |
Bulk file renamer — regex or numbered templates, safely |
Every pattern is stdlib-only (Python 3.10+) — clone and run, nothing to install:
python patterns/resilience/circuit_breaker.py
Every file in this repo was executed before inclusion by a run-gate: exit 0, real output, no traceback, and no third-party imports. The filter is simple and unforgiving — if it doesn't run on the standard library, it's not here. See COMPONENTS.md for the reusable classes inside each system.
MIT © 2026 Illia Hladkyi