Custom dictionary which can be accessed with glom-like paths
MIT License
Custom Dictionary with glom path compatible get, set and delete methods.
https://glom.readthedocs.io/en/latest/
For easy access to and operations on nested data.
python -m pip install glom-dict
>>> from glom_dict import GlomDict
>>> d = GlomDict(my_dict={"a": {"b": "c"}})
>>> d["my_dict.a.b"]
'c'
>>> d["my_dict.a.b"] = "C"
>>> d["my_dict.a.b"]
'C'
>>> d = GlomDict({'a': {'b': None}})
>>> d["a.b.c"]
Traceback (most recent call last):
...
PathAccessError: could not access 'c', index 2 in path Path('a', 'b', 'c'), got error: ...
from glom_dict import GlomDict, Path
>>> my_path = Path("a", "b", 1)
>>> d = GlomDict({"a": {"b": ["it", "works", "with", "lists", "too"]}})
>>> d[my_path]
'works'
For more examples refer to the excellent glom
tutorial.
https://glom.readthedocs.io/en/latest/tutorial.html
Based on collections.UserDict
Implemented methods
__getitem__
- glom.glom()
__setitem__
- glom.assign()
__delitem__
- glom.delete()
assign
- glom.assign()
- can pass missing
callable to automatically backfill missing structures.update
- Works but no special behavior