jsonl-diff 0.1.1__tar.gz → 0.2.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,398 @@
1
+ Metadata-Version: 2.4
2
+ Name: jsonl-diff
3
+ Version: 0.2.1
4
+ Summary: A lightweight tool for comparing large JSONL/NDJSON datasets without loading them entirely into memory.
5
+ Author-email: rmoralespp <rmoralespp@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2026 Rolando Morales Perez
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Source, https://github.com/rmoralespp/jsonl-diff
29
+ Project-URL: Homepage, https://github.com/rmoralespp/jsonl-diff
30
+ Project-URL: Changelog, https://github.com/rmoralespp/jsonl-diff/blob/main/CHANGELOG.md
31
+ Project-URL: Issues, https://github.com/rmoralespp/jsonl-diff/issues
32
+ Project-URL: Documentation, https://rmoralespp.github.io/jsonl-diff/
33
+ Keywords: jsonlines,ndjson,jsonl,json,gzip,bzip2,xz,zst,utilities,serialization,deserialization,diff,json-diff,cli
34
+ Classifier: Programming Language :: Python
35
+ Classifier: Programming Language :: Python :: 3 :: Only
36
+ Classifier: Programming Language :: Python :: 3.10
37
+ Classifier: Programming Language :: Python :: 3.11
38
+ Classifier: Programming Language :: Python :: 3.12
39
+ Classifier: Programming Language :: Python :: 3.13
40
+ Classifier: Programming Language :: Python :: 3.14
41
+ Classifier: Intended Audience :: Developers
42
+ Classifier: Intended Audience :: Information Technology
43
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
44
+ Classifier: Topic :: Internet
45
+ Classifier: Topic :: Utilities
46
+ Classifier: Topic :: File Formats :: JSON
47
+ Requires-Python: >=3.10
48
+ Description-Content-Type: text/markdown
49
+ License-File: LICENSE
50
+ Requires-Dist: ijson>=3.2
51
+ Requires-Dist: py-jsonl==1.5.3
52
+ Requires-Dist: jmespath>=1.0.0
53
+ Requires-Dist: msgspec>=0.21.1
54
+ Dynamic: license-file
55
+
56
+ <div align="center">
57
+
58
+ # jsonl-diff
59
+
60
+ ### A lightweight Python CLI and library for identity-aware JSON diffs
61
+
62
+ Compare large JSONL, NDJSON, and top-level JSON arrays by record identity—not
63
+ by line position—without loading either complete dataset into memory. Strict,
64
+ deterministic, and disk-backed.
65
+
66
+ [![PyPI](https://img.shields.io/pypi/v/jsonl-diff?style=flat-square&color=0A7BBB)](https://pypi.org/project/jsonl-diff/)
67
+ [![Python](https://img.shields.io/pypi/pyversions/jsonl-diff?style=flat-square)](https://pypi.org/project/jsonl-diff/)
68
+ [![CI](https://img.shields.io/github/actions/workflow/status/rmoralespp/jsonl-diff/ci.yml?branch=main&style=flat-square&label=CI)](https://github.com/rmoralespp/jsonl-diff/actions/workflows/ci.yml)
69
+ [![Coverage](https://img.shields.io/codecov/c/github/rmoralespp/jsonl-diff?style=flat-square)](https://codecov.io/gh/rmoralespp/jsonl-diff)
70
+ [![License](https://img.shields.io/github/license/rmoralespp/jsonl-diff?style=flat-square)](LICENSE)
71
+
72
+ [Install](#install) · [Quick start](#quick-start) · [CLI](#cli) · [Python API](#python-api) · [Semantics](#comparison-semantics) · [Documentation](#documentation)
73
+
74
+ </div>
75
+
76
+ ---
77
+
78
+ `jsonl-diff` reconciles two datasets using one or more top-level identity
79
+ fields. Record order does not matter. It reports what is equal, added, deleted,
80
+ modified, or duplicated while preserving the original OLD and NEW locations.
81
+
82
+ ```text
83
+ identity
84
+ OLD ── parse ── index ───┬─── compare ── summary / changes
85
+ NEW ── parse ── index ───┘
86
+ ```
87
+
88
+ ## Why jsonl-diff
89
+
90
+ | | |
91
+ |-----------------------------|--------------------------------------------------------------------------------------------------|
92
+ | **Scales beyond memory** | Streams both inputs and keeps the comparison index in SQLite. |
93
+ | **Matches real datasets** | Compares records by single or composite identity instead of line number. |
94
+ | **Stays deterministic** | Produces stable summaries, change order, and machine-readable details. |
95
+ | **Treats data strictly** | Rejects malformed input, invalid identities, and duplicates by default. |
96
+ | **Uses all available work** | Indexes OLD and NEW concurrently in isolated worker processes. |
97
+ | **Fits pipelines** | Supports filtering, ignored fields, compressed sources, schema drift, and meaningful exit codes. |
98
+
99
+ ## Install
100
+
101
+ ```bash
102
+ pip install jsonl-diff
103
+ ```
104
+
105
+ Requires **Python 3.10+**.
106
+
107
+ ## Quick start
108
+
109
+ Given `old.jsonl`:
110
+
111
+ ```jsonl
112
+ {"id":1,"name":"Ada"}
113
+ {"id":2,"name":"Grace"}
114
+ ```
115
+
116
+ and `new.jsonl`:
117
+
118
+ ```jsonl
119
+ {"id":2,"name":"Grace Hopper"}
120
+ {"name":"Ada","id":1}
121
+ {"id":3,"name":"Linus"}
122
+ ```
123
+
124
+ compare by `id`:
125
+
126
+ ```bash
127
+ jsonl-diff old.jsonl new.jsonl --key id
128
+ ```
129
+
130
+ ```text
131
+ Records:
132
+ equal: 1
133
+ added: 1
134
+ deleted: 0
135
+ modified: 1
136
+ OLD duplicates: 0
137
+ NEW duplicates: 0
138
+ ```
139
+
140
+ Property order and record order do not affect the result.
141
+
142
+ ## Core capabilities
143
+
144
+ - Single or composite top-level identities.
145
+ - Incremental JSONL/NDJSON and top-level JSON-array parsing.
146
+ - Disk-backed, parallel indexing for large datasets.
147
+ - Exact RFC 6901 ignore pointers.
148
+ - JMESPath record filtering.
149
+ - Configurable duplicate handling: `error`, `first`, or `last`.
150
+ - Representation-sensitive numeric comparison.
151
+ - Observed-schema drift for fields, types, nullability, and requiredness.
152
+ - Deterministic JSONL details output.
153
+ - Local, HTTP/HTTPS, file-like, and compressed sources.
154
+ - CLI and Python API backed by the same comparison engine.
155
+
156
+ ## CLI
157
+
158
+ ```text
159
+ jsonl-diff [-h] --key KEY [--ignore IGNORE] [--where EXPRESSION]
160
+ [--duplicates {error,first,last}] [--missing-key {error,null}]
161
+ [--details FILE] [--quiet]
162
+ [--schema-diff] [--schema-ignore POINTER] [--format {jsonl,json}]
163
+ old new
164
+ ```
165
+
166
+ | Option | Purpose |
167
+ |---------------------------|-----------------------------------------------------------------------|
168
+ | `old`, `new` | Local path, HTTP/HTTPS source, or `-` for stdin |
169
+ | `--key KEY` | Top-level identity field; repeat or comma-separate for composite keys |
170
+ | `--ignore POINTER` | RFC 6901 field pointer excluded from content comparison |
171
+ | `--where EXPRESSION` | JMESPath filter evaluated against each record |
172
+ | `--duplicates POLICY` | Reject duplicates or retain the `first`/`last` occurrence |
173
+ | `--missing-key POLICY` | Reject absent identity fields or treat them as `null` |
174
+ | `--details FILE` | Write deterministic machine-readable JSONL changes |
175
+ | `--schema-diff` | Compare observed fields, types, nullability, and requiredness |
176
+ | `--schema-ignore POINTER` | Exclude a pointer from observed-schema profiling |
177
+ | `--format FORMAT` | Read `jsonl` (default) or one top-level JSON array with `json` |
178
+ | `--quiet` | Suppress the human-readable summary |
179
+
180
+ ### Common workflows
181
+
182
+ **Composite identity**
183
+
184
+ ```bash
185
+ jsonl-diff old.jsonl new.jsonl --key country,customerId,type
186
+ ```
187
+
188
+ **Ignore volatile fields**
189
+
190
+ ```bash
191
+ jsonl-diff old.jsonl new.jsonl \
192
+ --key id \
193
+ --ignore /updated_at \
194
+ --ignore /metadata/request_id
195
+ ```
196
+
197
+ **Filter participating records**
198
+
199
+ ```bash
200
+ jsonl-diff old.jsonl new.jsonl \
201
+ --key id \
202
+ --where 'deleted_at == `null`'
203
+ ```
204
+
205
+ **Allow a missing composite-key component**
206
+
207
+ ```bash
208
+ jsonl-diff old.jsonl new.jsonl \
209
+ --key country,customerId \
210
+ --missing-key null
211
+ ```
212
+
213
+ **Detect observed-schema drift**
214
+
215
+ ```bash
216
+ jsonl-diff old.jsonl new.jsonl \
217
+ --key id \
218
+ --schema-diff \
219
+ --schema-ignore /metadata
220
+ ```
221
+
222
+ **Write a machine-readable change log**
223
+
224
+ ```bash
225
+ jsonl-diff old.jsonl new.jsonl \
226
+ --key id \
227
+ --details changes.jsonl \
228
+ --quiet
229
+ ```
230
+
231
+ Using the files from the quick start, `changes.jsonl` contains:
232
+
233
+ ```jsonl
234
+ {"duplicates":"error","ignore":[],"key":["id"],"missing_key":"error","type":"meta","where":null}
235
+ {"key":[2],"new_line":1,"old_line":2,"op":"modified","type":"change"}
236
+ {"key":[3],"new_line":3,"op":"added","type":"change"}
237
+ {"added":1,"deleted":0,"equal":1,"modified":1,"new_duplicates":0,"old_duplicates":0,"type":"summary"}
238
+ ```
239
+
240
+ The stream starts with comparison metadata, emits only changed identities in
241
+ deterministic order, and finishes with the complete summary. See the
242
+ [details format](docs/details-format.md) for duplicate and schema events.
243
+
244
+ **Read compressed inputs**
245
+
246
+ ```bash
247
+ jsonl-diff old.jsonl.xz new.jsonl.gz --key id
248
+ ```
249
+
250
+ **Read top-level JSON arrays**
251
+
252
+ ```bash
253
+ jsonl-diff old.json new.json --key id --format json
254
+ ```
255
+
256
+ ### Exit codes
257
+
258
+ | Code | Meaning |
259
+ |-----:|-------------------------------------------------------------|
260
+ | `0` | No record, duplicate, or requested schema differences |
261
+ | `1` | Record differences, tolerated duplicates, or schema changes |
262
+ | `2` | Input, resource, output, or runtime failure |
263
+ | `3` | Invalid configuration or CLI usage |
264
+
265
+ ## Python API
266
+
267
+ ```python
268
+ from jsonl_diff import ChangeOperation, diff
269
+
270
+
271
+ def main():
272
+ with diff(
273
+ "old.jsonl.gz",
274
+ "new.jsonl.gz",
275
+ key=("country", "customerId"),
276
+ ignore=("/updated_at",),
277
+ where='country == `"ES"`',
278
+ schema_diff=True,
279
+ ) as result:
280
+ print(result.summary)
281
+
282
+ for change in result.changes(ChangeOperation.MODIFIED):
283
+ print(change.key, change.old_line, change.new_line)
284
+
285
+ for change in result.schema_changes():
286
+ print(change.operation, change.path)
287
+
288
+
289
+ if __name__ == "__main__":
290
+ main()
291
+ ```
292
+
293
+ `diff()` returns a context-managed, disk-backed `DiffResult`. Entering the
294
+ context completely validates and indexes both sources. Changes, duplicates,
295
+ and schema changes are then iterated lazily instead of being materialized in
296
+ memory.
297
+
298
+ Applications must protect the entry point because indexing uses worker
299
+ processes. See [Parallel indexing](docs/parallel-indexing.md#application-entry-points)
300
+ for the multiprocessing requirements.
301
+
302
+ The immutable result models include:
303
+
304
+ - `Summary` and `SchemaSummary`
305
+ - `Change` and `SourceLocation`
306
+ - `Duplicate`
307
+ - `SchemaChange` and `SchemaFieldProfile`
308
+
309
+ The public exception hierarchy is rooted at `JsonlDiffError`:
310
+
311
+ - `ConfigurationError`
312
+ - `InputError`
313
+ - `DuplicateKeyError`
314
+ - `ResourceError`
315
+
316
+ See the [Python API reference](docs/python-api.md) for the complete signature,
317
+ models, iterator behavior, numeric key semantics, and error hierarchy.
318
+
319
+ ## Comparison semantics
320
+
321
+ The comparison is intentionally strict:
322
+
323
+ - Each JSONL line must contain exactly one valid top-level object.
324
+ - `--format json` requires one top-level array whose elements are records.
325
+ - Blank lines, malformed JSON, `NaN`, and infinities are rejected.
326
+ - Repeated object properties use last-wins semantics.
327
+ - Identity fields are top-level JSON values; nested identity paths are not supported.
328
+ - Object member order is ignored recursively; array order remains significant.
329
+ - JSON types remain distinct: `"1"` is not `1`, and `true` is not `1`.
330
+ - Parsed numeric representation remains significant: `1` is not `1.0`, and
331
+ `1.0` is not `1.00`.
332
+ - Unicode strings are compared without normalization.
333
+ - Duplicate identities fail unless `first` or `last` is explicitly selected.
334
+ - Changes are emitted in deterministic canonical-identity order.
335
+
336
+ `--where` decides which records participate. `--key` defines their identity.
337
+ `--ignore` excludes fields from content comparison. `--schema-ignore`
338
+ independently excludes fields from observed-schema profiling.
339
+
340
+ Read [Comparison semantics](docs/comparison-semantics.md) for duplicate rules,
341
+ ignore-pointer edge cases, filter order, schema inference, and numeric behavior.
342
+
343
+ ## Sources and compression
344
+
345
+ | Source | CLI | Python API |
346
+ |--------------------|:-----------:|:-----------:|
347
+ | Local path | Yes | Yes |
348
+ | HTTP/HTTPS URL | Yes | Yes |
349
+ | File-like object | No | Yes |
350
+ | gzip (`.gz`) | Yes | Yes |
351
+ | bzip2 (`.bz2`) | Yes | Yes |
352
+ | xz (`.xz`) | Yes | Yes |
353
+ | Zstandard (`.zst`) | Python 3.14 | Python 3.14 |
354
+ | ZIP archive | No | No |
355
+
356
+ Source opening and decompression are delegated to `py-jsonl`. File-like inputs
357
+ and stdin are staged in the private temporary workspace so both indexing
358
+ workers can reopen them.
359
+
360
+ ## Scope
361
+
362
+ `jsonl-diff` is a dataset reconciliation tool—not a visual or structural JSON
363
+ editor. It intentionally does not provide:
364
+
365
+ - line-position or field-level diffs;
366
+ - JSON Patch output;
367
+ - move or rename detection;
368
+ - nested identities or automatic key detection;
369
+ - fuzzy matching or numeric tolerances;
370
+ - unordered-array comparison;
371
+ - declared-schema validation or input repair;
372
+ - ZIP, database, or cloud-provider inputs;
373
+ - GUI or HTML reports.
374
+
375
+ ## Documentation
376
+
377
+ | Guide | Covers |
378
+ |------------------------------------------------------|--------------------------------------------------------------------|
379
+ | [Comparison semantics](docs/comparison-semantics.md) | Identity, duplicates, ignores, filtering, numbers, and determinism |
380
+ | [Disk-backed architecture](docs/architecture.md) | SQLite indexes, temporary storage, cleanup, and source handling |
381
+ | [Parallel indexing](docs/parallel-indexing.md) | Worker lifecycle, database merge, recovery, and entry points |
382
+ | [Details format](docs/details-format.md) | Machine-readable JSONL event contract |
383
+ | [Python API](docs/python-api.md) | Complete signature, models, iterators, and errors |
384
+
385
+ ## Development
386
+
387
+ ```bash
388
+ uv sync --group test --group lint
389
+ uv run pytest
390
+ uv run ruff check --quiet --output-format=concise .
391
+ ```
392
+
393
+ The suite covers CLI behavior, identity and canonicalization, validation,
394
+ details output, source handling, compression, parallel indexing, and cleanup.
395
+
396
+ ## License
397
+
398
+ Licensed under the terms in [LICENSE](LICENSE).