Skip to main content

An implementation of nested dictionaries

Project description

Python PyPI - Status PyPI - License PyPI - Python Version Read the Docs Test Codecov GitHub Release PyPI - Version

Version française disponible


ndict-tools

In standard Python, dictionaries within dictionaries are possible, creating nested data structures. However, while this functionality exists, Python does not offer native features to easily search and manage keys and values within complex nested dictionaries.

My research and testing of libraries dedicated to managing nested dictionaries led me to several solutions, but none fully met my expectations. The module I found that came closest was one from 2015, available on PyPI, but it does not provide a complete architecture for managing "nested dictionary objects" in a smooth and robust way.

This motivated me to redevelop such a module, offering a more complete and intuitive way to handle nested dictionaries. This new module makes it easier to manipulate, search, and manage keys and values in complex data structures by providing tools dedicated to this specific task.

What is a Nested Dictionary?

A nested dictionary is simply a dictionary where the values themselves are dictionaries. This allows for the creation of richer, hierarchical data structures where each "node" in the structure can hold additional information in the form of dictionaries, making it easier to model complex data in an organized and accessible way.

Using Nested Keys and Managing Hierarchies in Dictionaries

Keys of Different Types and Using Lists for Hierarchical Keys

Just like with standard dictionaries in Python, the keys in a nested dictionary must be hashable. This means you can use types such as numbers, strings, or even tuples as keys. However, lists are not hashable and cannot be used directly as keys.

Accessing Nested Values

Nested dictionaries allow you to structure your data over multiple levels. For example, to access a value in a nested dictionary, you can use a sequence of keys that represents each level of the hierarchy.

Using simple, non-nested lists is the way used to represent nested keys.

Nested Access Example

The following two expressions are equivalent for accessing a value in a nested dictionary:

dictionary[[1, "a", (2, 3)]]   # is equivalent to
dictionary[1]["a"][(2, 3)]

Installation

pip install ndict-tools

Documentation

Full documentation is available at ndict-tools.readthedocs.io.

Contributing

See CONTRIBUTING.md for setup instructions and contribution guidelines.

License

This project is licensed under the CeCILL-C Free Software License.

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

ndict_tools-1.2.0.tar.gz (152.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ndict_tools-1.2.0-py3-none-any.whl (44.1 kB view details)

Uploaded Python 3

File details

Details for the file ndict_tools-1.2.0.tar.gz.

File metadata

  • Download URL: ndict_tools-1.2.0.tar.gz
  • Upload date:
  • Size: 152.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ndict_tools-1.2.0.tar.gz
Algorithm Hash digest
SHA256 4913dec9e00836b0045580c03c425f6634c5fb83f24a91e2d3d758156a18de3f
MD5 1f9e5cd4cdb14d7327d024ab8f5a67c8
BLAKE2b-256 643ba8e7adcfbd5c37705eaabcd3d13be5e32a306e4ebc80ce58336ae4fe712f

See more details on using hashes here.

File details

Details for the file ndict_tools-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: ndict_tools-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 44.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for ndict_tools-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7bc126b94f6402ee4812cb0edebc7d6bd1c06614cc8b43a2524aac429f3c5ae0
MD5 df83dbe571d4bc3487831fb253409090
BLAKE2b-256 226a9ca822e412b88cfee53cdafa84734b4ef421eead6d7d90863608fad4b02c

See more details on using hashes here.

Supported by

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