dictknife

raw JSON →
0.14.2 verified Fri May 01 auth: no python

Utility set for handling dict in Python. Current version 0.14.2, requires Python >=3.10. Release cadence is irregular, with minor version bumps over years.

pip install dictknife
error ImportError: cannot import name 'deep_merge' from 'dictknife'
cause Old version of dictknife (<0.9) had deep_merge under a different name or not available.
fix
Upgrade dictknife to latest: pip install --upgrade dictknife
error TypeError: deep_merge() got an unexpected keyword argument 'conflict'
cause Previously deep_merge accepted a 'conflict' argument to resolve conflicts, removed in v0.14.
fix
Remove the 'conflict' argument; merge now always overwrites. See docs for custom conflict resolution.
error ModuleNotFoundError: No module named 'dictknife.csv'
cause Submodule csv was removed in v0.14.0.
fix
Use top-level import: from dictknife import load_csv
gotcha deep_merge modifies the first dict in-place. Did not in older versions (<0.14).
fix Pass a deepcopy if you need to preserve original: from copy import deepcopy; merged = deep_merge(deepcopy(d1), d2)
deprecated Functions from submodules like `dictknife.csv` and `dictknife.json` are moved to top-level. Importing `from dictknife.csv import load_csv` still works but is deprecated.
fix Use `from dictknife import load_csv` instead.
breaking Python 3.10 is now required. Versions <0.14.2 supported Python 3.6+.
fix Upgrade Python to >=3.10 or pin dictknife<0.14.2.

Demonstrates deep_merge and DictWalker.

from dictknife import deep_merge, DictWalker

d1 = {'a': 1, 'b': {'x': 10}}
d2 = {'b': {'y': 20}, 'c': 3}
merged = deep_merge(d1, d2)
print(merged)
# {'a': 1, 'b': {'x': 10, 'y': 20}, 'c': 3}

walker = DictWalker(d1)
for path, value in walker.walk():
    print(path, value)