Skip to content

myfjin/awesome-python-patterns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 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.

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

The patterns

Data Structures (18)

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

Monitoring & Observability (12)

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

Performance (11)

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

Distributed Systems (9)

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

Networking (9)

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

Algorithms & Reasoning (9)

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

I/O & Parsing (8)

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

Architecture (7)

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

Async & Concurrency (5)

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

Resilience (4)

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

Persistence (3)

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

Security (3)

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

Vision (1)

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

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.

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 and checksum. 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

License

Stars

2 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages