Skip to main content

Utilities for Python nested dictionaries.

Project description

Build Coverage Status PyPI Version PyPI - Python Version License

🪆 Nested Dict Tools

Nested Dict Tools is a Python package that provides utilities for working with nested dictionaries. It includes:

  • Recursive types for describing nested mappings and dictionaries.
  • Fully typed functions to:
    • Flatten and unflatten nested dictionaries.
    • Get and set deeply nested values.
from nested_dict_tools import flatten_dict, unflatten_dict, get_deep, set_deep

nested = {'a': {'b': {'c': 42}}}

# Get a deeply nested value
value = get_deep(nested, ['a', 'b'])
print(value)  # Output: {'c': 42}

# Set a deeply nested value
set_deep(nested, ['a', 'z'], 'new_value')
print(nested)  # Output: {'a': {'b': {'c': 42}, 'z': 'new_value'}}

# Flatten the nested dictionary
flat = flatten_dict(nested, sep='.')
print(flat)  # Output: {'a.b.c': 42, 'a.z': 'new_value'}

# Unflatten the flattened dictionary
unflattened = unflatten_dict(flat, sep='.')
print(unflattened == nested)  # Output: True

# Recursive types:
type NestedDict[K, V] = dict[K, NestedDictNode[K, V]]
type NestedDictNode[K, V] = V | NestedDict[K, V]
# Similar types for Mapping and MutableMapping

⬇️ Installation

You can install Nested Dict Tools via pip:

pip install nested-dict-tools

🧾 License

MIT

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

nested_dict_tools-0.1.3.tar.gz (69.4 kB view details)

Uploaded Source

Built Distribution

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

nested_dict_tools-0.1.3-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file nested_dict_tools-0.1.3.tar.gz.

File metadata

  • Download URL: nested_dict_tools-0.1.3.tar.gz
  • Upload date:
  • Size: 69.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.2

File hashes

Hashes for nested_dict_tools-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6c3136c1c4c7b8b2480ce4b4b38712a74183adba1ac6941eb9d4a32944158340
MD5 9cb8de6cbe5f8e9150f1d44e76a174de
BLAKE2b-256 466f881013ba58816a647a9135941e2857f685c164a83041c964b48c32a93a96

See more details on using hashes here.

File details

Details for the file nested_dict_tools-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for nested_dict_tools-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 8ba9c7faf13eb3c2cc33076f5453ea631cf5aea9e0d6d837b60aefa8f6a36aed
MD5 4a9f78dcf14233363000b6280bd66036
BLAKE2b-256 69e438db23ce5538a53a5617c97ba9881094ade8f18d79592b764915c164123f

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