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.1.tar.gz
(66.4 kB
view details)
Built Distribution
File details
Details for the file nested_dict_tools-0.1.1.tar.gz
.
File metadata
- Download URL: nested_dict_tools-0.1.1.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 | 0681c9f25a5f166031271385e8cea9dc10bfd6787e8b65c1add437cd1110207d |
|
MD5 | 99271078ba15b96b47c17ff6c760d8fc |
|
BLAKE2b-256 | a57400978ea9fc66845b605084299f0eb377de809bb524c1a48a2a49ccab3893 |
File details
Details for the file nested_dict_tools-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: nested_dict_tools-0.1.1-py3-none-any.whl
- Upload date:
- Size: 6.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a7c128f9fd41aa35bc397d83f4687c2f62e00a2a00eb71619bd05c3809178b3 |
|
MD5 | 27af8f3382420c470dbe8ad778a3ecf8 |
|
BLAKE2b-256 | 7b6fa4f1fa383213b67b2dbe83efda57523567ed36e5bb2b833df31b6eb36b04 |