Utilities for Python nested dictionaries.
Project description
🪆 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
Project details
Release history Release notifications | RSS feed
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)
Built Distribution
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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92898aa6561d5c49c819ed85cd4386d01683bf6605cb3730b60d22c8562f7db4 |
|
MD5 | 11d79294cfc647318a7a7d44e6e861f7 |
|
BLAKE2b-256 | eb740c24979a0ddba58955e1a24203e0c7868e117cf5271ac5c7ac0b8cb50d7a |
File details
Details for the file nested_dict_tools-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: nested_dict_tools-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4d0a07153f3571c76c2fb3572f63108af8d86915daaa003fc5c3c86d4409569 |
|
MD5 | b8d66ea235175133451db4c371c4acd5 |
|
BLAKE2b-256 | 665581b9ac0f815c0ba7a102db1752cc772a4d7416e4d08957c16520d5d2e912 |