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.
    • Map functions on leaves.
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.2.1.tar.gz (70.7 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.2.1-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for nested_dict_tools-0.2.1.tar.gz
Algorithm Hash digest
SHA256 28674e55211694b392afb477824c0f32ee0ccb0276d1d3b7cfcd32060a0ee574
MD5 5d502cb7488893cd4df56309291525a1
BLAKE2b-256 5868bb9931c640ad6e01306d8c609f0335363166680b975bec87dec93fdd2268

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nested_dict_tools-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3568cff87e7be5b195d8840ca565341360a8edb67989257ed390711f395999d8
MD5 29d48b1337f12a0fafb009876af6b6e2
BLAKE2b-256 1149ebc30e9409e9ebbd570c1e559fee16f41f88d3518cf0571cf5960e87b570

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