sigmaepsilon.deepdict
is a lightweight Python library designed to handle nested dictionaries more easily, especially in cases where dictionaries are created dynamically. Its key feature is the DeepDict
class, which extends the regular dict to support nested layouts. It allows easy manipulation of deeply nested structures, array-like indexing, and automatic creation of deep dictionary levels without manually defining all parent keys. It is particularly useful in scenarios involving hierarchical data. The library also supports printing dictionaries as trees.
The first implementation of the DeepDict
class was based on this StackOverflow thread.
-
Nested Layout Support: DeepDict allows for seamless manipulation of deeply nested structures, enabling array-like indexing and automatic creation of nested dictionary levels without the need to manually define all parent keys.
-
Parent-Child Awareness: Each sub-dictionary within a DeepDict is aware of its parent container, providing attributes like key, address, and parent.key to facilitate navigation and management of the nested structure.
-
Tree Representation: With the optional installation of the asciitree library, DeepDict can print dictionaries as trees, offering a visual representation of the nested data.
from sigmaepsilon.deepdict import DeepDict
# Creating a DeepDict instance
data = DeepDict()
data["a", 0, "b", 1, 5] = 10
# Accessing attributes
print(data["a", 0, "b"].key) # Output: 'b'
print(data["a", 0, "b"].address) # Output: ['a', 0, 'b']
print(data["a", 0, "b"].parent.key) # Output: 0
See the documentation for more examples and explanation on behaviour.
The documentation is built with Sphinx using the PyData Sphinx Theme and hosted on ReadTheDocs.
For installation instructions, please refer to the documentation.
This package is licensed under the MIT license.