Dotty-Dict¶
Info: | Dictionary wrapper for quick access to deeply nested keys. |
---|---|
Author: | Paweł Zadrożny @pawelzny <pawel.zny@gmail.com> |
Features¶
- Simple wrapper around python dictionary and dict like objects
- Two wrappers with the same dict are considered equal
- Access to deeply nested keys with dot notation:
dot['deeply.nested.key']
- Create, read, update and delete nested keys of any length
- Expose all dictionary methods like
.get
,.pop
,.keys
and other
Installation¶
pipenv install dotty-dict # or pip install dotty-dict
Documentation¶
- Full documentation: http://dotty-dict.readthedocs.io
- Public API: http://dotty-dict.readthedocs.io/en/latest/api.html
- Examples and usage ideas: http://dotty-dict.readthedocs.io/en/latest/examples.html
TODO¶
- key=value caching to speed up lookups and low down memory consumption
Quick Example¶
Create new dotty using factory function.
>>> from dotty_dict import dotty
>>> dot = dotty({'plain': {'old': {'python': 'dictionary'}}})
>>> dot['plain.old']
{'python': 'dictionary'}
You can start with empty dotty
>>> from dotty_dict import dotty
>>> dot = dotty()
>>> dot['very.deeply.nested.thing'] = 'spam'
>>> dot
Dotty(dictionary={'very': {'deeply': {'nested': {'thing': 'spam'}}}}, separator='.', esc_char='\\')
>>> dot['very.deeply.spam'] = 'indeed'
>>> dot
Dotty(dictionary={'very': {'deeply': {'nested': {'thing': 'spam'}, 'spam': 'indeed'}}}, separator='.', esc_char='\\')
>>> del dot['very.deeply.nested']
>>> dot
Dotty(dictionary={'very': {'deeply': {'spam': 'indeed'}}}, separator='.', esc_char='\\')
>>> dot.get('very.not_existing.key')
None