Skip to main content

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

  1. Auto-suggest mappingssuggest(source, target) returns matches with confidence scores in [0, 1] and a reason (exact, normalized, abbreviation, fuzzy).
  2. Normalization enginenormalize("CustomerID") == "customer id". Collapses case, separators, camelCase, digit boundaries and abbreviations.
  3. Abbreviation dictionary — safe defaults (qty->quantity, dob->date of birth, ...). Risky short words (min, long, st) are opt-in via build_table(aggressive=True); extend with build_table({"abbr": "expansion"}).
  4. Mapping persistencesave_mapping / load_mapping as YAML or JSON, chosen by file extension. Round-trips are lossless.
  5. Validationvalidate(mapping, source_columns=, target_columns=) reports unmapped, stale, and colliding columns.
  6. Applyapply_map(data, mapping) renames columns on list[dict] records or dict[str, list] columnar data; unmapped columns pass through.
  7. Value mappingdetect_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mapmonkey-1.1.1.tar.gz (50.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mapmonkey-1.1.1-py3-none-any.whl (29.0 kB view details)

Uploaded Python 3

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

Hashes for mapmonkey-1.1.1.tar.gz
Algorithm Hash digest
SHA256 75ec01973335b7bc9771071cd013b04fe0dfcc3ea5eb2bf2c1c6c180ef3d2539
MD5 b3e83074eb9f3c9f3aa6dc5bfc4e411c
BLAKE2b-256 4202b4c0c7ee12a0438327e09e561f56fdbb2452e8e6619e6eca176ae90e79d4

See more details on using hashes here.

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

Hashes for mapmonkey-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 340de856d020b14962826ea3707b829718ac5cdca5d5abe43fa415b2a2c409e5
MD5 e6907264095f061e589db1e29c903b51
BLAKE2b-256 eec12b3185dde4b4ea47baab34ed89902b67325ca1e22176ee3546bcb5c034ae

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page