utility set of handling dict
Project description
features
deepmerge
deepequal
walker
deepmerge
from dictknife import deepmerge
d0 = {
"a": {
"x": 1
},
"b": {
"y": 10
},
}
d1 = {
"a": {
"x": 1
},
"b": {
"z": 10
},
"c": 100
}
actual = self._callFUT(d0, d1)
expected = {
"a": {
"x": 1
},
"b": {
"y": 10,
"z": 10
},
"c": 100
}
assert actual == expected
walker
using LooseDictWalkingIterator example.
import json
import pprint
from dictknife import LooseDictWalkingIterator
# from: https://github.com/BigstickCarpet/json-schema-ref-parser
d = json.loads("""
{
"definitions": {
"person": {
"$ref": "schemas/people/Bruce-Wayne.json"
},
"place": {
"$ref": "schemas/places.yaml#/definitions/Gotham-City"
},
"thing": {
"$ref": "http://wayne-enterprises.com/things/batmobile"
},
"color": {
"$ref": "#/definitions/thing/properties/colors/black-as-the-night"
}
}
}
""")
refs = []
iterator = LooseDictWalkingIterator(["$ref"])
for path, sd in iterator.iterate(d):
refs.append((path[:], sd["$ref"]))
pprint.pprint(refs)
output
[(['definitions', 'color', '$ref'],
'#/definitions/thing/properties/colors/black-as-the-night'),
(['definitions', 'place', '$ref'],
'schemas/places.yaml#/definitions/Gotham-City'),
(['definitions', 'thing', '$ref'],
'http://wayne-enterprises.com/things/batmobile'),
(['definitions', 'person', '$ref'], 'schemas/people/Bruce-Wayne.json')]
todo: description about chains and operator and context,…
command
install dictknife via pip install dictknife[command].
concat
transform
diff
TODO: gentle introduction
concat
$ dicknife concat a.yaml b.yaml c.json
transform
$ transform --function misc/transform.py:lift --src src/01transform/properties.yaml --name person
# or
$ dictknife transform --code 'lambda d,name=None: {"definitions": {name: d}}' --src src/01transform/properties.yaml --name person
diff
$ dictknife diff a.yaml b.yaml
$ dictknife diff --sort-keys a.yaml b.yaml
0.3
command extras pip install dictknife[command]
adding dictknife-concat command
adding dictknife-transform command
adding dictknife-diff command
0.2
external iterator is recommened. (using LooseDictWalkingIterator instead of LooseDictWalker)
0.1
yaml/json load extras (pip install dictknife[load])
Project details
Release history Release notifications | RSS feed
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dictknife-0.3.tar.gz.
File metadata
- Download URL: dictknife-0.3.tar.gz
- Upload date:
- Size: 7.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1471b52cf2a2cb6e7f18dc632926c778648659301b2c729fd4542410ac43f201
|
|
| MD5 |
452dff98a4c3b531bf1121ed4c21f49d
|
|
| BLAKE2b-256 |
30f39d3609ce6547195476c4cb1ac19d4e72af1fe8c171a60f80a2d8c40bae5e
|
File details
Details for the file dictknife-0.3-py2.py3-none-any.whl.
File metadata
- Download URL: dictknife-0.3-py2.py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9e2e2fc4141b8c34d3d474bae78e45bf29da21461a6841617775c37deb95499
|
|
| MD5 |
b3e442cd5b33de89be5eeb98e574e893
|
|
| BLAKE2b-256 |
ab600ac8ad7073e21766f4ee0e8d73ac8e1a5ccef4d2088a512c4c72aa6ddbfc
|