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.7.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

patchdiff-0.3.7-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: patchdiff-0.3.7.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for patchdiff-0.3.7.tar.gz
Algorithm Hash digest
SHA256 dfa4699aa416a9e4e838ddf9368c18281b8b7db771fe3b9c2171fbcd6597580e
MD5 68c4a6f4a1fe2d467d95552927caa964
BLAKE2b-256 5e751bc2ba493d94be2cb00425ca01fa1bdad5084dbcd9497641331bae198953

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchdiff-0.3.7.tar.gz:

Publisher: ci.yml on fork-tongue/patchdiff

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: patchdiff-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for patchdiff-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 b9c5890f0bd94a60ad2244963c25082558547dfcd8e55ec02cca9b6b1f7652dc
MD5 8ac2b91958a825f271381c46a2ee7e61
BLAKE2b-256 8072fea7fecf2c77fecff074bf57e4b8cd3dc8275e1e8b351d4e24464fad3f13

See more details on using hashes here.

Provenance

The following attestation bundles were made for patchdiff-0.3.7-py3-none-any.whl:

Publisher: ci.yml on fork-tongue/patchdiff

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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