Skip to content

Linked dictionaries with a self-replicating default factory.

License

Notifications You must be signed in to change notification settings

sigma-epsilon/sigmaepsilon.deepdict

Repository files navigation

SigmaEpsilon.DeepDict - A lightweight Python library for nested dictionaries

CircleCI codecov Codacy Badge Documentation Status License PyPI - Downloads PyPI - Version PyPI - Python Version Code style: black Static Badge

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.

Key Features

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

Example Usage

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.

Documentation

The documentation is built with Sphinx using the PyData Sphinx Theme and hosted on ReadTheDocs.

Installation

For installation instructions, please refer to the documentation.

License

This package is licensed under the MIT license.

About

Linked dictionaries with a self-replicating default factory.

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •