https://github.com/stef/objchanges
diffs and patches python objects
https://github.com/stef/objchanges
Last synced: over 1 year ago
JSON representation
diffs and patches python objects
- Host: GitHub
- URL: https://github.com/stef/objchanges
- Owner: stef
- Created: 2019-03-05T02:43:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-05-20T19:29:04.000Z (about 6 years ago)
- Last Synced: 2025-02-01T23:17:19.754Z (over 1 year ago)
- Language: Python
- Size: 34.2 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
!objchanges
can diff simple python objects consisting only of dicts/lists/atomic types, but
is also able to apply the diffs as patches to existing objects. also included
is a fuzzer that creates random objects to test objchanges.
if the objects are supported this should work fine
```
assert diff(new, patch(old, diff(old, new))) in [None, []]
assert diff(old, revert(new, diff(old, new))) in [None, []]
```
you can now also display the changes nicely formatted in a ANSI terminal:
```
old = {...}
new = {... something changed ... }
d = diff(old,new)
print(contextdiff(new, p))
```
!!cmdline
you can also invoke objchanges directly on json files:
```
% cat new
{"a": [{"5": {"1": 3}, "2": {"2": "sZ5"}}, ["ezw", []]], "1": 23, "c": "m0L"}
% cat old
{"a": [{"5": {"1": 3}, "2": {"2": "sZ5"}}, ["ezw"]], "1": 23, "c": "m0L"}
# running simple diff
% ./objchanges.py diff old new
[{"type": "added", "path": ["a", 1], "data": ["ezw", []]}, {"type": "deleted", "path": ["a", 1], "data": ["ezw"]}]
# patching old with diff
% ./objchanges.py patch old <(./objchanges.py diff old new)
{"a": [{"5": {"1": 3}, "2": {"2": "sZ5"}}, ["ezw", []]], "1": 23, "c": "m0L"}
# reverting new with diff
% ./objchanges.py revert new <(./objchanges.py diff old new)
{"a": [{"5": {"1": 3}, "2": {"2": "sZ5"}}, ["ezw"]], "1": 23, "c": "m0L"}
```