Skip to main content

Type-aware, key-based structural diffing of tabular datasets with human- and machine-readable reports.

Project description

diffmonkey

Type-aware, key-based structural diffing of tabular datasets — answer "what changed between last month's export and this month's?" in one call, with human- and machine-readable reports.

diffmonkey matches rows by a key column (or composite key), compares the remaining columns with type awareness (numbers by value, dates by calendar date, booleans by truth, strings whitespace-normalised, nulls unified), and buckets the result into added / removed / changed / unchanged with summary statistics. It is built on the rexbytes ecosystem — typemonkey for type inference and number parsing, datemonkey for date parsing, cleanmonkey for whitespace and invisible-character normalisation — so it does not re-derive those wheels.

In scope: structural comparison, change detection, change reporting. Out of scope: merge/reconciliation, text diffing, schema migration, version control.

Install

pip install diffmonkey            # CSV/TSV/pipe input built in
pip install "diffmonkey[excel]"   # add .xlsx reading (openpyxl)

Requires Python 3.11+.

Quick start

from diffmonkey import compare

old = [{"id": "1", "name": "Widget", "price": "1,234"},
       {"id": "2", "name": "Gadget", "price": "50"}]
new = [{"id": "1", "name": "Widget", "price": "1234"},   # price reformatted, not changed
       {"id": "3", "name": "Gizmo",  "price": "9"}]       # id 2 removed, id 3 added

result = compare(old, new, key="id")

print(result.summary.one_line())
# 1 added, 1 removed, 0 changed (of 2 current), 0 unchanged

print(result.to_markdown())   # human report
result.to_dict()              # machine-readable
result.write_csv("changes.csv")

"1,234" vs "1234" is not reported as a change — type-aware numeric comparison sees one number. The same applies to "01/02/2025" vs "2025-01-02" (dates, with a locale hint), " foo " vs "foo" (whitespace), and None/""/"NA" (nulls).

CLI

diffmonkey compare old.csv new.csv --key id
diffmonkey compare old.csv new.csv --key region,sku --ignore updated_at --format markdown
diffmonkey compare old.xlsx new.xlsx --key id --format json -o diff.json

Exit code is 0 when the datasets are identical and 1 when they differ — handy in CI and scripts.

Key options

Option Purpose
key Identity column, or list for a composite key
columns / ignore Restrict / exclude columns from comparison
column_map={"old":"new"} Handle renamed columns (avoids false add+remove)
rel_tol / abs_tol Floating-point tolerance for numeric columns
locale="us" / "eu" Disambiguate slash dates and number separators
null_equivalent Treat all null spellings as one value (default on)
type_aware / date_aware Toggle type/date-aware comparison
include_unchanged Retain unchanged rows in the result
on_duplicate / on_missing_key Policies for messy keys

Output formats

  • result.to_dict() — JSON-serialisable structure
  • result.to_markdown() — report for PRs, chat, email
  • result.to_html() — standalone HTML diff report
  • result.to_csv() / result.write_csv(path) — one row per field change

Using with AI assistants

See SKILL.md for LLM-oriented usage (decision tree, worked examples, anti-patterns). See LIMITATIONS.md for the deliberate design tradeoffs (date/locale ambiguity, null vocabulary, duplicate handling) so behaviour that looks surprising is not mistaken for a bug.

License

MIT — see LICENSE.

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

diffmonkey-1.0.0.tar.gz (45.8 kB view details)

Uploaded Source

Built Distribution

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

diffmonkey-1.0.0-py3-none-any.whl (26.0 kB view details)

Uploaded Python 3

File details

Details for the file diffmonkey-1.0.0.tar.gz.

File metadata

  • Download URL: diffmonkey-1.0.0.tar.gz
  • Upload date:
  • Size: 45.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for diffmonkey-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0b978b9015e7fe61206c83b1a74b2b16cb4e737a225a28216025e5f204310b92
MD5 06b578fc06102dece26eb7fe8ab09d1b
BLAKE2b-256 e885998ca7e237fe72abbb41c823b1e5949e27b728b29464a47afdca2e02cfda

See more details on using hashes here.

File details

Details for the file diffmonkey-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: diffmonkey-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 26.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for diffmonkey-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 398897c4b068240d6d40c6e83cd6a51b49ea61757ceddc1e5184f22857a6af0c
MD5 a3fc4dc542861b9126b732c6e7a62dc9
BLAKE2b-256 2c84c0bd65c120831e327061b8877c06749adfbdee0b22d341232021807fb701

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