Skip to content

Kilo59/glom-dict

Repository files navigation

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

Details

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