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.2.0.tar.gz
(71.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nested_dict_tools-0.2.0.tar.gz.
File metadata
- Download URL: nested_dict_tools-0.2.0.tar.gz
- Upload date:
- Size: 71.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
320d9746a494aec92a3a07a1b566ec2fc41b374098db1acf58da075470b4d6a1
|
|
| MD5 |
362f9cfc07be70671bfa1e2a183bc018
|
|
| BLAKE2b-256 |
3be9a5727a737aa8d6ffa45990fb0f5737886eb3a551f1b21c90a83b18e406ff
|
File details
Details for the file nested_dict_tools-0.2.0-py3-none-any.whl.
File metadata
- Download URL: nested_dict_tools-0.2.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c3200a9e969df23a826aab0ca4395ff36d0f78c4d67130d378103ede9a1c1842
|
|
| MD5 |
33c43d3a12f6b2bccde1dce26a722e7e
|
|
| BLAKE2b-256 |
373d17bf49b34bd3268b9d5fdfbe060f0989f9460cdcdd11dc284f3c9ce78725
|