Project description
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"
# }
# ]
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages .
Source Distribution
Built Distribution
File details
Details for the file patchdiff-0.3.4.tar.gz
.
File metadata
Download URL:
patchdiff-0.3.4.tar.gz
Upload date: Jan 19, 2023
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
Copy
MD5
be122026b6fb26f6f9cf61ff6f226d41
Copy
BLAKE2b-256
bc69b8922aa25ee91663013833daca845c9b7db22dd0293ac3717c7e37e45c97
Copy
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: Jan 19, 2023
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
Copy
MD5
b20cd7b3e534d3897fc3be4511e235e4
Copy
BLAKE2b-256
710ba08db71cadf50e812a0c1ff221fa7486910caedd3098239b97226fb05a39
Copy
See more details on using hashes here.