Skip to main content

Custom Dictionary with glom get, set and del methods

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

glom-dict-0.0.2a0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

glom_dict-0.0.2a0-py3-none-any.whl (3.6 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page