Skip to main content

222

English | 中文

两个字典的结构差异,嵌套键以点号路径呈现。

安装

pip install 222

用法

from p222 import apply_diff, dict_diff

left = {"db": {"port": 5432, "host": "a"}, "tags": ["x"], "gone": 1}
right = {"db": {"port": 6543, "host": "a"}, "tags": ["y"], "new": 2}

dict_diff(left, right)
# {'db.port': ('changed', 5432, 6543),
#  'gone':    ('removed', 1, None),
#  'new':     ('added', None, 2),
#  'tags':    ('changed', ['x'], ['y'])}

apply_diff(left, dict_diff(left, right)) == right   # True

说明

包名以数字开头,导入名是 p222。嵌套 dict 递归比较,变化落在 db.pool.size 这样的路径上,而不是整棵子树被替换。apply_diff 可反向应用,满足 apply_diff(left, dict_diff(left, right)) == right。

许可证

MIT


English

Structural diff between two dicts, nested keys included.

Install

pip install 222

Usage

from p222 import apply_diff, dict_diff

left = {"db": {"port": 5432, "host": "a"}, "tags": ["x"], "gone": 1}
right = {"db": {"port": 6543, "host": "a"}, "tags": ["y"], "new": 2}

dict_diff(left, right)
# {'db.port': ('changed', 5432, 6543),
#  'gone':    ('removed', 1, None),
#  'new':     ('added', None, 2),
#  'tags':    ('changed', ['x'], ['y'])}

apply_diff(left, dict_diff(left, right)) == right   # True

Notes

The import name is p222 because the distribution starts with a digit. Nested dicts are compared recursively and reported as dotted paths such as db.pool.size. apply_diff reverses the diff, so the round trip is exact.

License

MIT

Metadata

Release files for 222 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for 222 0.0.4
File Size Uploaded Provenance
222-0.0.4.tar.gz 3.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for 222 0.0.4
File Interpreter ABI Platform
222-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / 222-0.0.4.tar.gz

Download URL 222-0.0.4.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4ac08c15b30587bcbe39a2195de7ec9075b2d26ba0c3d939fc46a23c7a33a20f
BLAKE2b-256 checksum
How to use checksums
ce9af7c8f1e006f993e8a3ecced7aca08bafa0f7f3e49e39351ad7bffdf0d120
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Release files / 222-0.0.4-py3-none-any.whl

Download URL 222-0.0.4-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
03d20f5475d2b9c7430e8b53b1054df5490056188a13c9b7df42571feef095a5
BLAKE2b-256 checksum
How to use checksums
05cfb5eeebd0522fd9e6e883fdf205963bbe5425ad19995d3ff39b6dcef49659
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.11

Security for 222 0.0.4

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page