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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: nested_dict_tools-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 5135571724b8e1fcd4306cade6a346a566828aa7c292223e9420382ea0557dcd
MD5 304643c85531ffc966027a67d5353b97
BLAKE2b-256 45719d3773f67c04786f92528777cde9af527459fb1c32aedd63786d353c6de2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for nested_dict_tools-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4c0463932dd9f0b84bbbf02eaaa2915f877b29788b80bba2bda6a081ddaf5a71
MD5 616d3ec1df4618804bd415b07c4a967a
BLAKE2b-256 c66c9b1d2ed6652883469e9a0cfc9a0b0b238eeaa2d2840c99f08b955ad3fbe8

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