Python Examples
render_table aligned plain-text output
Build a column-aligned plain-text table from headers and rows, with optional right alignment for numbers. Good for CLI reports and quick log dumps.
strict base64 encode and decode helpers
Strict base64 helpers for text and bytes: encode to ASCII, decode while tolerating whitespace and missing padding, and reject corrupt input with ValueError.
validate with per-field error messages
Field-level validator that checks required values, formats and numeric ranges, returning a {field: message} mapping ready for an API error response.
parse_json with positional error messages
Decode JSON from a string or file and convert json.JSONDecodeError into a message with line and column, plus friendlier handling of empty documents.
build_query and parse_query round-trip
Merge default parameters, encode lists as repeated keys and parse query strings back into simple values or lists, without manual string concatenation.
run_in_pool bounded thread scheduler
Run zero-argument callables on a bounded thread pool and get results back in input order, with per-task exceptions captured instead of aborting the batch.
fetch_json with timeout and error mapping
urllib GET that parses JSON, applies a timeout and turns HTTP, network and decode failures into one RuntimeError with the reason. No requests dependency.
read_env and read_int typed config
Read strings, integers and booleans from environment variables with defaults and a ConfigError that names the bad variable. Nice for 12-factor app settings.
TokenBucket rate limiter with bursts
Thread-safe token bucket that lets short bursts through while enforcing a steady average rate; use it to pace API calls or crawl politeness.
LRUCache backed by OrderedDict with stats
OrderedDict-backed LRU cache that evicts the oldest touched entry once capacity is reached, while counting hits and misses for a quick cache-ratio check.
sort_records using a custom comparator
Sort list-of-dict records by several fields with an explicit comparator, grouping None values at the end and keeping ties stable. Ideal for report tables.
batched_chunks over lazy iterables
Turn any iterable, including generators, into fixed-size lists for bulk API calls, pagination or progress reporting without loading everything first.
iter_text_lines streaming for big files
Generator that yields a text file line by line, so multi-gigabyte logs can be processed with constant memory instead of reading everything at once.
deep_clone and deep_merge for nested dicts
Deep-copy nested dictionaries and lists, then merge an override without aliasing the originals. Handy for layered config defaults before mutating them.
retry_with_backoff decorator with jitter
Decorator that retries a flaky callable with capped exponential backoff and full random jitter, so transient network or disk errors stop failing your job.