diffx
Python bindings for diffx - semantic diff for structured data (JSON, YAML, TOML, XML, INI, CSV). Powered by Rust via PyO3 for blazing fast performance.
Installation
pip install diffx
Supported Platforms
| Platform | Architecture |
|---|---|
| Linux | x64 (glibc) |
| Linux | x64 (musl/Alpine) |
| Linux | ARM64 |
| macOS | x64 (Intel) |
| macOS | ARM64 (Apple Silicon) |
| Windows | x64 |
Usage
Basic Diff
import diffx
old = {"name": "Alice", "age": 30}
new = {"name": "Alice", "age": 31, "city": "Tokyo"}
results = diffx.diff(old, new)
for change in results:
print(f"{change['type']}: {change['path']}")
# Modified: age
# Added: city
With Options
results = diffx.diff(data1, data2,
epsilon=0.001, # Tolerance for float comparison
array_id_key='id', # Match array elements by ID
ignore_keys_regex='timestamp|updatedAt', # Ignore keys matching regex
path_filter='user', # Only show diffs in paths containing "user"
ignore_case=True, # Ignore case differences
ignore_whitespace=True, # Ignore whitespace differences
)
Parsers
Parse various formats to Python objects:
import diffx
json_obj = diffx.parse_json('{"name": "Alice"}')
yaml_obj = diffx.parse_yaml('name: Alice\nage: 30')
toml_obj = diffx.parse_toml('name = "Alice"')
csv_list = diffx.parse_csv('name,age\nAlice,30')
ini_obj = diffx.parse_ini('[user]\nname = Alice')
xml_obj = diffx.parse_xml('<user><name>Alice</name></user>')
Format Output
import diffx
results = diffx.diff(old, new)
print(diffx.format_output(results, 'json')) # JSON format
print(diffx.format_output(results, 'yaml')) # YAML format
print(diffx.format_output(results, 'diffx')) # diffx format
File Comparison
import diffx
# Compare files (auto-detects format from extension)
results = diffx.diff_files('old.json', 'new.json')
results = diffx.diff_files('config1.yaml', 'config2.yaml', epsilon=0.1)
# Compare strings
json1 = '{"name": "Alice", "age": 30}'
json2 = '{"name": "Alice", "age": 31}'
results = diffx.diff_strings(json1, json2, 'json')
API Reference
diff(old, new, **kwargs)
Compare two values and return differences.
Options (kwargs):
| Option | Type | Description |
|---|---|---|
epsilon |
float | Tolerance for floating-point comparisons |
array_id_key |
str | Key to identify array elements |
ignore_keys_regex |
str | Regex pattern for keys to ignore |
path_filter |
str | Only show diffs in matching paths |
output_format |
str | Output format ("diffx", "json", "yaml") |
ignore_whitespace |
bool | Ignore whitespace differences |
ignore_case |
bool | Ignore case differences |
brief_mode |
bool | Report only whether objects differ |
quiet_mode |
bool | Suppress normal output |
Returns: List of diff results:
# For Added/Removed:
{"type": "Added", "path": "key", "value": ...}
{"type": "Removed", "path": "key", "value": ...}
# For Modified/TypeChanged:
{"type": "Modified", "path": "key", "old_value": ..., "new_value": ...}
{"type": "TypeChanged", "path": "key", "old_value": ..., "new_value": ...}
Parsers
parse_json(content: str) -> Anyparse_yaml(content: str) -> Anyparse_toml(content: str) -> dictparse_csv(content: str) -> list[dict]parse_ini(content: str) -> dictparse_xml(content: str) -> dict
Utility Functions
format_output(results: list, format: str) -> str- Format diff results as stringdiff_files(file1: str, file2: str, **kwargs) -> list- Compare two filesdiff_strings(str1: str, str2: str, format: str, **kwargs) -> list- Compare two strings
Exception
DiffError- Raised when diff operations fail
Development
# Setup
uv sync --all-extras
# Build
uv run maturin develop
# Test
uv run pytest -v
# Format & Lint
cargo fmt --check
cargo clippy
License
MIT
Metadata
Release files for diffx-python 0.7.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
Total release size: 7.8 MB
Release files / diffx_python-0.7.2-cp311-cp311-win_amd64.whl
| Download URL | diffx_python-0.7.2-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 1.1 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
4b140fe13e1ae3f2b411d3306284a7c78eb1ca1aeb6741e7011ef041c0ace586
|
|
BLAKE2b-256 checksum How to use checksums |
9533a65d64cbb4fe8e06448efebcc2707cf09596befee5d2fc2ae56ed087e3f6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / diffx_python-0.7.2-cp311-cp311-musllinux_1_1_x86_64.whl
| Download URL | diffx_python-0.7.2-cp311-cp311-musllinux_1_1_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.11 Linux musl 1.1+ x86-64 |
|
SHA-256 checksum How to use checksums |
051ed95c3706ff712c62ab58005d60120ee4ed7a207ee213c5d1ce1f28e7895f
|
|
BLAKE2b-256 checksum How to use checksums |
59d7c2d3b17cfca3f8baeee058c73c591319edd1cca4b718c2fb11d2ad7509e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / diffx_python-0.7.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | diffx_python-0.7.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.4 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
6ec00d54be726f559121abe17a391d213ec6bd4d2cb778a8f76e217cf13f44c4
|
|
BLAKE2b-256 checksum How to use checksums |
1a2ce5d325fb805d72faed16063024c36070bd03af3ba57974885a0623ebeefb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / diffx_python-0.7.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | diffx_python-0.7.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.3 MB |
| Tags | CPython 3.11 Linux glibc 2.17+ ARM64 |
|
SHA-256 checksum How to use checksums |
3f5af1a3bcd2d1eb4c109ff54ed7716634c19700d2b61dbebc3742b5b2885805
|
|
BLAKE2b-256 checksum How to use checksums |
9b5868283f899f87b4f32c5951636443991a108a570a326ca08685a0e64ca211
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / diffx_python-0.7.2-cp311-cp311-macosx_11_0_arm64.whl
| Download URL | diffx_python-0.7.2-cp311-cp311-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.11 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
02f2d52eb03615e469d6d6e37403781a9ba66cade5c451f8ad5349a4e89eb418
|
|
BLAKE2b-256 checksum How to use checksums |
c42ec642c258b1435338a859e33058d6c0e11fb109a821ff820d1445e0833a61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Release files / diffx_python-0.7.2-cp311-cp311-macosx_10_12_x86_64.whl
| Download URL | diffx_python-0.7.2-cp311-cp311-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.2 MB |
| Tags | CPython 3.11 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
79e18e9f5a9038d10471acf7b90d2c69f893d4329f9df97f21456c12a027cbe6
|
|
BLAKE2b-256 checksum How to use checksums |
6be317c0faa35a00168b1e36e5f0c88d765276b2fb7bdd9c9a16917b96bb6aa8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.12
|
Security for diffx-python 0.7.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.