deflate-dict
raw JSON → 1.2.2 verified Mon Apr 27 auth: no python
A Python library for inflating and deflating nested dictionaries. Deflate flattens nested dicts into key paths, and inflate reverses the process. Current version 1.2.2, stable maintenance.
pip install deflate-dict Common errors
error TypeError: unhashable type: 'list' ↓
cause Passing a list as a value deeply nested; deflate expects dicts as nested structures.
fix
Ensure nested values are dicts, not lists. Wrap lists in a dict if needed.
error KeyError: 'some.path' ↓
cause Inflation attempted on a flat dict missing some expected keys or using wrong separator.
fix
Check that the flat dict contains keys exactly matching the deflated output, or use custom separator consistently.
Warnings
gotcha Default separator is '.' which can clash with keys containing dots. Use `separator` parameter to choose a safe delimiter. ↓
fix deflate(nested, separator='__') or inflate(flat, separator='__')
gotcha Inflation assumes no overlapping key paths. If a flattened key like 'a.b' and a nested key like 'a' with value exist, behavior may be unexpected. ↓
fix Ensure no ambiguous key patterns before inflating.
gotcha The library does not handle non-string keys for deflation. Keys must be strings or convertible to strings. ↓
fix Convert non-string keys to strings before deflating.
Imports
- deflate wrong
from deflate_dict.deflate import deflatecorrectfrom deflate_dict import deflate - inflate wrong
from deflate_dict.inflate import inflatecorrectfrom deflate_dict import inflate
Quickstart
from deflate_dict import deflate, inflate
nested = {'a': {'b': 1, 'c': 2}}
flat = deflate(nested)
print(flat) # {'a.b': 1, 'a.c': 2}
restored = inflate(flat)
print(restored) # {'a': {'b': 1, 'c': 2}}