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.0.tar.gz (66.4 kB view details)

Uploaded Source

Built Distribution

nested_dict_tools-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: nested_dict_tools-0.1.0.tar.gz
  • Upload date:
  • Size: 66.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.0.tar.gz
Algorithm Hash digest
SHA256 92898aa6561d5c49c819ed85cd4386d01683bf6605cb3730b60d22c8562f7db4
MD5 11d79294cfc647318a7a7d44e6e861f7
BLAKE2b-256 eb740c24979a0ddba58955e1a24203e0c7868e117cf5271ac5c7ac0b8cb50d7a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nested_dict_tools-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f4d0a07153f3571c76c2fb3572f63108af8d86915daaa003fc5c3c86d4409569
MD5 b8d66ea235175133451db4c371c4acd5
BLAKE2b-256 665581b9ac0f815c0ba7a102db1752cc772a4d7416e4d08957c16520d5d2e912

See more details on using hashes here.

Supported by

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