Python Examples

PythonOct 23, 2026

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.

formattingtableterminalcli
000
PythonOct 23, 2026

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.

bytesdecodingencodingbase64
000
PythonOct 23, 2026

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.

emailerrorsvalidationforms
000
PythonOct 23, 2026

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.

debuggingerror-handlingparsingjson
000
PythonOct 23, 2026

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.

urllibquery-stringurlencoding
000
PythonOct 23, 2026

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.

concurrencyfutureserrorsthread-pool
000
PythonOct 23, 2026

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.

urllibhttpjsontimeout
000
PythonOct 23, 2026

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.

environmentconfiguration12-factorvalidation
000
PythonOct 23, 2026

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.

concurrencytoken-bucketrate-limitthrottling
000
PythonOct 23, 2026

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.

evictionlruordereddictcache
000
PythonOct 23, 2026

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.

sortingrecordsnull-handlingcomparator
000
PythonOct 23, 2026

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.

batchingchunkinggeneratoriterable
000
PythonOct 23, 2026

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.

streaminglinesfile-iomemory
000
PythonOct 23, 2026

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.

dictmergedeep-copynested-data
000
PythonOct 23, 2026

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.

decoratorbackoffretryjitter
000