https://github.com/kilo59/glom-dict
Custom dictionary which can be accessed with glom-like paths
https://github.com/kilo59/glom-dict
dict dictionaries glom nested-structures python
Last synced: 3 months ago
JSON representation
Custom dictionary which can be accessed with glom-like paths
- Host: GitHub
- URL: https://github.com/kilo59/glom-dict
- Owner: Kilo59
- License: mit
- Created: 2021-09-04T19:41:02.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2025-02-11T00:01:21.000Z (4 months ago)
- Last Synced: 2025-03-15T06:13:43.413Z (3 months ago)
- Topics: dict, dictionaries, glom, nested-structures, python
- Language: Python
- Homepage: https://kilo59.github.io/glom-dict/
- Size: 414 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# glom-dict
[](https://github.com/Kilo59/glom-dict/actions)
[](https://glom_dict.github.io/glom-dict/)
[](https://pypi.org/project/glom-dict/)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
```bash
python -m pip install glom-dict
```## Examples
```python
>>> 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.
```python
>>> 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
```python
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
- [x] `__getitem__` - `glom.glom()`
- [x] `__setitem__` - `glom.assign()`
- [x] `__delitem__` - `glom.delete()`
- [x] `assign` - `glom.assign()` - can pass `missing` callable to automatically backfill missing structures.
- [ ] `update` - Works but no special behavior