Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

awesome-python-patterns

Not a link list, and not idiom snippets — 99 runnable, run-gated, stdlib-only Python patterns.

Every file in this repository:

  • runspython3 patterns/<category>/<pattern>.py executes a working demo/self-test, standard library only, no pip install, no network;
  • passed a run-gate — executed end-to-end, per-pattern, logged (see gate_logs/) before it was allowed in;
  • is real implementation — data structures, distributed-systems machinery, resilience patterns — not toy pseudocode;
  • ships with its own doc — every <pattern>.py has a <pattern>.md beside it: what it does, the guarantee its self-test actually asserts, and the checkable constraints, quoted from the code rather than described around it.

Quick start

git clone https://github.com/myfjin/awesome-python-patterns
cd awesome-python-patterns
python3 patterns/distributed/raft_consensus.py     # watch a Raft cluster elect a leader
python3 patterns/data_structures/red_black_tree.py # watch a red-black tree stay balanced
python3 tools/run_gate.py                          # run the whole gate yourself
cat patterns/data_structures/bloom_filter.md       # the doc that ships beside every pattern

The patterns

Data Structures (18)

Pattern What it is Doc
avl_tree AVL Tree Implementation md
binary_indexed_tree Binary Indexed Tree md
bloom_filter Bloom Filter md
fenwick_tree Fenwick Tree (Binary Indexed Tree) implementation with comprehensive functionality. md
interval_tree Interval Tree md
kd_tree A complete k-d tree implementation for 2D points with insert, nearest neighbor, md
merkle_tree A simple Merkle tree implementation using SHA-256 hashing. md
ordered_map Ordered Map md
persistent_deque Persistent Deque md
priority_task_scheduler Priority Queue Scheduler Module md
radix_tree Radix Tree md
red_black_tree Red Black Tree md
segment_tree Segment Tree md
skip_list Skip List md
suffix_array Suffix Array md
treap Treap md
trie Trie (Prefix Tree) implementation with autocomplete functionality. md
union_find Union Find md

Monitoring & Observability (12)

Pattern What it is Doc
alert_manager Alert Manager md
event_logger Structured event logger with rotation capabilities. md
log_pattern_matcher Log Pattern Matcher md
metric_aggregation_engine Metric Aggregation Engine md
metric_aggregator Metric aggregator with tags for counters, gauges, and histograms. md
metrics_formatter Metrics Formatter md
time_series_db In-memory time-series database module with support for insertion, querying, md
timer_stack Timer Stack md
trace_collector Trace Collector md
trace_sampler Distributed Tracing Sampler Module md
trace_span_collector Distributed Tracing Span Collector Module md
window_sampler Anomaly Detection Sampler Module md

Performance (11)

Pattern What it is Doc
batch_controller Adaptive Batch Size Controller md
budget_allocator Request Collapser Module md
free_list_allocator Free List Allocator md
hyperloglog HyperLogLog probabilistic cardinality estimator implementation. md
job_scheduler A simple job scheduler with cron-like expressions. md
lru_cache Lru Cache md
object_pool_allocator Object Pool Allocator md
resource_budget_allocator Resource Budget Allocator Module md
rw_lock Rw Lock md
token_bucket Token Bucket md
work_stealing_queue Work-Stealing Queue Implementation md

Distributed Systems (9)

Pattern What it is Doc
consistent_hash_ring Consistent Hash Ring Implementation md
crdt_sets CRDT Sets Implementation md
distributed_lock_manager Distributed Lock Manager md
g_counter_crdt Distributed Counter Implementation md
gossip_protocol Gossip Protocol Membership List Implementation md
quorum_consensus Quorum consensus simulator module. md
raft_consensus Raft Consensus Algorithm Implementation md
service_registry Service Registry md
vector_clock Vector Clock implementation for detecting causal relationships between events md

Networking (9)

Pattern What it is Doc
connection_pool Connection Manager with Pooling md
connection_pool_health_checks Connection Pool with Health Checks Module md
dns_cache Dns Cache md
http_retry_client HTTP Client with Retry, Backoff, and Circuit Breaker Support md
http_router HTTP Request Multiplexer Module md
packet_parser Packet Parser md
rate_limiter Rate Limiter md
rtt_estimator Round-trip time estimator module with EWMA smoothing and timeout calculation. md
url_router Url Router md

Algorithms & Reasoning (9)

Pattern What it is Doc
astar_pathfinding A* Pathfinding Algorithm Implementation md
bayesian_network Bayesian Belief Network Implementation md
csp_solver Constraint Satisfaction Problem (CSP) Solver Module md
decision_tree Simple Decision Tree Classifier md
dependency_graph Dependency Graph Resolver - Topological Sort Implementation md
expression_evaluator Simple Expression Evaluator with Variables md
minimax_game_search A complete minimax game solver with alpha-beta pruning and depth limiting. md
rule_engine Rule-based inference engine with forward chaining and conflict resolution. md
sat_solver Sat Solver md

I/O & Parsing (8)

Pattern What it is Doc
arg_parser Arg Parser md
chunked_reader Line-delimited file parser with chunked reads. md
csv_to_json CSV to JSON converter module with type inference, nested key support, and streaming. md
csv_validator CSV Validator and Transformer Module md
diff_engine A simple diff engine for text comparison. md
ini_parser Simple INI file parser module. md
log_parser JSON Schema Validator Module md
template_engine Template Engine md

Architecture (7)

Pattern What it is Doc
cqrs_bus Simple CQRS Command/Query Splitter Module md
event_bus Event Bus with Typed Channels md
event_sourcing_store Event Sourcing Store Implementation md
message_encoder Message Format Encoder/Decoder Module md
plugin_registry Plugin registry with lazy loading, dependency management, and entry point discovery. md
saga_coordinator Saga Pattern Coordinator Module md
state_machine Simple State Machine Engine md

Async & Concurrency (5)

Pattern What it is Doc
async_task_queue Async Task Queue with Priority and Retries md
cancellable_task_group Async task group implementation with cancellation support. md
priority_queue_scheduler Priority Queue with Deadline Scheduling Module md
pubsub_broker A simple pub-sub message broker implementation with wildcard topic matching. md
reactive_signals Reactive Signals md

Resilience (4)

Pattern What it is Doc
bulkhead_isolator Bulkhead Pattern Isolator Module md
circuit_breaker Circuit Breaker md
dead_letter_queue Dead Letter Queue Handler Module md
timeout_guard Timeout Guard md

Persistence (3)

Pattern What it is Doc
lsm_tree LSM-Tree Engine Implementation md
segmented_wal Write-Ahead Log (WAL) implementation for durable transaction logging. md
write_ahead_log Write-Ahead Log (WAL) implementation for data durability and crash recovery. md

Security (3)

Pattern What it is Doc
capability_access Capability-Based Access Control System md
hotp_totp Time-Based One-Time Password (TOTP) generator and validator. md
secure_envelope Secure Envelope Module md

Vision (1)

Pattern What it is Doc
image_stats Histogram-based image contrast stretcher module. md

Quality bar

"Run-gated" means: we do not claim a pattern works — we run it, on the commit that ships it, and keep the log. The gate script ships in this repo — one command lets you re-verify every claim yourself — and CI re-runs it on every push. If a pattern is listed here, it executed cleanly with a 90-second timeout on the day of the commit.

Two verification instruments (which one you're holding)

This free sample's verifier is tools/run_gate.py — it re-runs all 99 patterns in this repo and is the command to use here. The full AURA Pattern Library (1,024 patterns / 1,500 files across Python, C++, Go, Rust, R and JavaScript) has a second, library-wide instrument, tools/census.py, which sweeps every file for run-validity, real assertions, and determinism (3 runs, byte-identical output) and reconciles the counts against the signed catalog. census.py ships with the full library, not with this sample — if an email or doc pointed you at it, on this repo the equivalent command is python3 tools/run_gate.py. Full-library access (including census.py and its reproducible census results) is available on request.

Provenance — stated honestly

These patterns were machine-harvested from qwen3-coder:480b (Apache 2.0, via Ollama cloud), then human-curated: de-duplicated, categorized, policy-checked (stdlib-only), defect-fixed, and run-gated per file. MANIFEST.json maps every pattern to its harvest session, its checksum, and the checksum of its doc — all 198 hashes regenerated and verified against the files on 2026-08-07. We think the honest description of this collection is: AI-generated, human-verified.

C++ twins — available now

Every pattern in this repo has a modern C++17 twin — compiled and self-tested on macOS (ARM64) and Linux (x86-64), delivered side-by-side with its Python original, verification logs included. The free tier is this repo, complete, forever.

Get the C++ Twins → — $29, all 99 patterns, free updates for life.

License

MIT — see LICENSE.

About

99 runnable, run-gated, stdlib-only Python patterns — not a link list

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages