Metadata-Version: 2.4
Name: diffmonkey
Version: 1.0.0
Summary: Type-aware, key-based structural diffing of tabular datasets with human- and machine-readable reports.
Author-email: RexBytes <pythonic@rexbytes.com>
License: MIT License
        
        Copyright (c) 2026 RexBytes
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/RexBytes/diffmonkey
Project-URL: Issues, https://github.com/RexBytes/diffmonkey/issues
Keywords: diff,csv,tabular,compare,dataset,changes,reconciliation
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: cleanmonkey
Requires-Dist: typemonkey
Requires-Dist: datemonkey
Provides-Extra: excel
Requires-Dist: openpyxl>=3.0; extra == "excel"
Provides-Extra: dsv
Requires-Dist: dsvmonkey; extra == "dsv"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Requires-Dist: hypothesis>=6.0; extra == "dev"
Dynamic: license-file

# 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

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

Requires Python 3.11+.

## Quick start

```python
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

```bash
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`](./SKILL.md) for LLM-oriented usage (decision tree, worked
examples, anti-patterns). See [`LIMITATIONS.md`](./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`](./LICENSE).

[`typemonkey`]: https://pypi.org/project/typemonkey/
[`datemonkey`]: https://pypi.org/project/datemonkey/
[`cleanmonkey`]: https://pypi.org/project/cleanmonkey/
