Skip to content

Recipes

The mappingtools primitives (Operators, Collectors, Lenses, Transformers) are designed to be highly composable.

Below are real-world recipes demonstrating how to combine these mathematical engines to solve complex IT, data, and architectural problems.

You can find the executable code for all of these recipes in the recipes/ folder on GitHub.

Organization

Recipes are grouped by domain to help you find solutions relevant to your work. Within each domain, the recipes are ordered progressively—starting from foundational concepts and building up to more advanced architectural patterns.


Data Engineering & ETL

Convert a flat stream of dicts (like a CSV or DB cursor) into a nested dictionary using reshape and Aggregation.

Convert dataclasses, datetime objects, and custom Python structures directly into JSON-serializable dictionaries using strictify.

Combine AutoMapper and strictify to recursively rewrite verbose JSON string keys into sequentially generated, ultra-compact shortcodes to save network bandwidth.

Combine reshape and Aggregation.ALL to group a flat stream of transactional records into an N-dimensional analytical tensor without losing any underlying individual records.

Configuration & State Management

Load multiple configuration layers and fold them into a single state using functools.reduce and merge.

Combine flatten and MappingCollector (with Aggregation.ALL) to instantly find duplicated values (like IPs or secrets) scattered across deeply nested configuration files.

Combine itertools.product and merge to instantly generate an N-dimensional matrix of fully-formed configurations for hyperparameter tuning or parameterized testing.

Combine native Python comprehensions and distinct to isolate feature flags across an N-tier configuration cascade ( Global -> Region -> User) and detect conflicting state overrides.

Security, Auditing & Governance

Find additions, removals, and changes between two complex JSON payloads by collapsing them with flatten.

Combine flatten, hashlib, and Lens optics to locate and cryptographically mask sensitive secrets (PII, Tokens) deep within an N-dimensional JSON payload before logging.

Combine native dictionary comprehensions, rename, and Lens optics to strip internal metadata, reshape schemas, and cryptographically mask sensitive fields before sending a database record to an external API client.

Architecture & Microservices

Immutably update deep nested sections of a JSON payload using Lens and merge.

Combine the inverse operator with the AutoMapper collector to compute the blast radius of an infrastructure outage and generate a minified Mermaid.js node visualization.

Combine flatten, Lens, and merge to build an auto-correction pipeline that casts types, migrates deprecated keys, and applies structural defaults to incoming JSON payloads.

Use the Dictifier wrapper to instantly proxy method calls and attribute accesses across a vast fleet of identically typed objects simultaneously.

Use inverse and rekey to instantly build a two-way synchronization bridge (snake_case <-> camelCase) between a Python backend and a React/Vue frontend payload.

Combine flatten, Lens, patch, and merge to derive a public API contract from a canonical internal JSON Schema by pruning internal/read-only fields and overlaying partner-specific constraints.

Combine flatten, Lens, patch, and merge to preserve a JSON Schema's object shape while replacing each primitive field, scalar array item, direct $ref, and direct union/composition schema (oneOf, anyOf, allOf) with a oneOf wrapper representing either an override value or an approval decision. If the root schema has a $id, the recipe also appends a suffix so the derived schema gets a distinct identity.

Use the combine operator alongside the Resolver, LogicalResolver, and NumericResolver enums (or a custom callable) to deeply merge two trees while precisely controlling how collisions at the leaf level are resolved (e.g., FAIL, ALL, AND, SUM).

Telemetry & Analytics

Wrap generic configurations in MeteredDict to track "hot" read/write paths and identify dead code.

Traverse a filesystem and simultaneously categorize files by extension, size bucket, and hidden status using a single CategoryCounter.

Use MappingCollector and Aggregation.EMA to automatically calculate an Exponential Moving Average across a noisy stream of live data ticks grouped by their sensor source.

Combine MeteredDict, Dictifier, and reduce(merge, ...) to effortlessly broadcast metric collection across a distributed fleet of isolated workers and instantly fold their results into a single global telemetry map.

Use MappingCollector with Aggregation.EMA to maintain a memory-efficient baseline of a noisy time-series and instantly flag incoming data points that deviate beyond a set threshold.

Algorithmic Explorations

Combine reshape and Lens optics to convert a flat stream of MIDI events into a nested musical score, and immutably transpose a specific instrument track without mutating the original composition.

Combine reshape and Lens optics to convert a flat 1D stream of RGB pixels into a 2D spatial tensor (Row -> Col -> RGB) and apply a Grayscale filter specifically to a central bounding box.

Use flatten to expand a nested graph traversal and extract all unique nodes reachable within a specific sub-graph generated from an Adjacency List.

Combine MappingCollector and Aggregation.COUNT to instantly build a Markov Transition Matrix (Word -> Counter(Next Words)) from a training corpus, and use it to hallucinate new sentences.