Skip to main content

MIT

Project description

PyPI version CI status

Patchdiff 🔍

Based on rfc6902 this library provides a simple API to generate bi-directional diffs between composite python datastructures composed out of lists, sets, tuples and dicts. The diffs are jsonpatch compliant, and can optionally be serialized to json format. Patchdiff can also be used to apply lists of patches to objects, both in-place or on a deepcopy of the input.

Install

pip install patchdiff

Quick-start

from patchdiff import apply, diff, iapply, to_json

input = {"a": [5, 7, 9, {"a", "b", "c"}], "b": 6}
output = {"a": [5, 2, 9, {"b", "c"}], "b": 6, "c": 7}

ops, reverse_ops = diff(input, output)

assert apply(input, ops) == output
assert apply(output, reverse_ops) == input

iapply(input, ops)  # apply in-place
assert input == output

print(to_json(ops, indent=4))
# [
#     {
#         "op": "add",
#         "path": "/c",
#         "value": 7
#     },
#     {
#         "op": "replace",
#         "path": "/a/1",
#         "value": 2
#     },
#     {
#         "op": "remove",
#         "path": "/a/3/a"
#     }
# ]

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

patchdiff-0.3.4.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

patchdiff-0.3.4-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file patchdiff-0.3.4.tar.gz.

File metadata

  • Download URL: patchdiff-0.3.4.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for patchdiff-0.3.4.tar.gz
Algorithm Hash digest
SHA256 034959a4a6e4143b2f63ae645b221e0617909410ffb3e186b77c643225e233e6
MD5 be122026b6fb26f6f9cf61ff6f226d41
BLAKE2b-256 bc69b8922aa25ee91663013833daca845c9b7db22dd0293ac3717c7e37e45c97

See more details on using hashes here.

File details

Details for the file patchdiff-0.3.4-py3-none-any.whl.

File metadata

  • Download URL: patchdiff-0.3.4-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for patchdiff-0.3.4-py3-none-any.whl
Algorithm Hash digest
SHA256 109710036e028aa0bac10139997a42b7d69d73d0275eff12455a59f2d6f8f995
MD5 b20cd7b3e534d3897fc3be4511e235e4
BLAKE2b-256 710ba08db71cadf50e812a0c1ff221fa7486910caedd3098239b97226fb05a39

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page