Skip to content

glom_dict¤

ci documentation pypi version

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.

Installation¤

python -m pip install glom-dict

Examples¤

>>> 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'

Better error messages.¤

>>> 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: ...

Glom Paths¤

from glom_dict import GlomDict, Path
>>> d = GlomDict({"a": {"b": ["works", "with", "lists", "too"]}})
>>> d[Path("a", "b", 0)]
'works'

For more examples refer to the excellent glom tutorial. https://glom.readthedocs.io/en/latest/tutorial.html

Details¤

Based on collections.UserDict

Implemented methods

  • __getitem__ - glom.glom()
  • __setitem__ - glom.assign()
  • __delitem__ - glom.delete()
  • update - Works but no special behavior