Fuzzy column mapping between source and target schemas: suggest, validate, persist, and apply column + value mappings.
Project description
mapmonkey
Fuzzy column mapping between source and target schemas. Source has
First Name, target needs first_name; two files have Customer ID vs
customer_id vs CustomerID vs cust_id. mapmonkey suggests the mapping with
confidence scores, lets you save and reuse it, validates it against real
schemas, and applies the renames (and value rewrites) to your data.
Part of the monkey toolkit. MIT licensed.
Install
pip install mapmonkey
Depends on cleanmonkey (invisible
character / whitespace normalization) and PyYAML.
Quick start
from mapmonkey import suggest, apply_map, save_mapping, load_mapping
source = ["First Name", "Last Name", "Customer ID", "qty"]
target = ["first_name", "last_name", "customer_id", "quantity"]
suggestion = suggest(source, target)
for m in suggestion.matches:
print(f"{m.source} -> {m.target} ({m.confidence:.2f}, {m.reason})")
# First Name -> first_name (0.95, normalized)
# Customer ID -> customer_id (0.95, normalized)
# qty -> quantity (0.95, abbreviation)
mapping = suggestion.to_mapping()
save_mapping(mapping, "customers.yaml") # reuse it later
rows = [{"First Name": "Ann", "qty": "3"}]
apply_map(rows, load_mapping("customers.yaml"))
# [{'first_name': 'Ann', 'quantity': '3'}]
What it does
- Auto-suggest mappings —
suggest(source, target)returns matches with confidence scores in[0, 1]and a reason (exact,normalized,abbreviation,fuzzy). - Normalization engine —
normalize("CustomerID") == "customer id". Collapses case, separators, camelCase, digit boundaries and abbreviations. - Abbreviation dictionary — safe defaults (
qty->quantity,dob->date of birth, ...). Risky short words (min,long,st) are opt-in viabuild_table(aggressive=True); extend withbuild_table({"abbr": "expansion"}). - Mapping persistence —
save_mapping/load_mappingas YAML or JSON, chosen by file extension. Round-trips are lossless. - Validation —
validate(mapping, source_columns=, target_columns=)reports unmapped, stale, and colliding columns. - Apply —
apply_map(data, mapping)renames columns onlist[dict]records ordict[str, list]columnar data; unmapped columns pass through. - Value mapping —
detect_value_map(["M", "F"]) == {"M": "Male", "F": "Female"};apply_value_map(values, vmap)rewrites cells, keeping unknown values.
CLI
mapmonkey suggest --source a.csv --target b.csv --out map.yaml
mapmonkey apply --map map.yaml --input a.csv --output renamed.csv
mapmonkey validate --map map.yaml --source a.csv --target b.csv
suggest also accepts --source-cols "a,b,c" instead of a file, a
--threshold, and --interactive to confirm each match.
Using with AI assistants
See SKILL.md for an LLM-consumable quick reference (decision
tree, worked examples, troubleshooting). See LIMITATIONS.md
for deliberate design tradeoffs before "fixing" surprising behaviour.
Development & review
See CONTRIBUTING.md for the testing philosophy and the
competitive multi-model review process. The release decision is rubric-based:
RELEASE_READINESS.md defines the gates and score, and
python scripts/readiness.py computes it (history in
REVIEW_HISTORY.md).
Scope
In scope: column-name matching, fuzzy matching, abbreviation expansion,
mapping persistence, value mapping. Out of scope: data transformation beyond
renaming and type conversion (use typemonkey).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mapmonkey-1.1.1.tar.gz.
File metadata
- Download URL: mapmonkey-1.1.1.tar.gz
- Upload date:
- Size: 50.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75ec01973335b7bc9771071cd013b04fe0dfcc3ea5eb2bf2c1c6c180ef3d2539
|
|
| MD5 |
b3e83074eb9f3c9f3aa6dc5bfc4e411c
|
|
| BLAKE2b-256 |
4202b4c0c7ee12a0438327e09e561f56fdbb2452e8e6619e6eca176ae90e79d4
|
File details
Details for the file mapmonkey-1.1.1-py3-none-any.whl.
File metadata
- Download URL: mapmonkey-1.1.1-py3-none-any.whl
- Upload date:
- Size: 29.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
340de856d020b14962826ea3707b829718ac5cdca5d5abe43fa415b2a2c409e5
|
|
| MD5 |
e6907264095f061e589db1e29c903b51
|
|
| BLAKE2b-256 |
eec12b3185dde4b4ea47baab34ed89902b67325ca1e22176ee3546bcb5c034ae
|