A Python library designed for deep-merging, updating, and compressing dictionaries.
Project description
dictpress
Simple dictionary manipulation utilities for Python.
Repository: https://github.com/allen2c/dictpress PyPI: https://pypi.org/project/dictpress/
Installation
pip install dictpress
Usage
from dictpress import flatten_dict, unflatten_dict, merge, get_deep, set_deep
# Flatten nested dictionaries
data = {"a": {"b": {"c": 1}}, "x": 2}
flattened = flatten_dict(data)
# {"a.b.c": 1, "x": 2}
# Unflatten back to nested structure
nested = unflatten_dict(flattened)
# {"a": {"b": {"c": 1}}, "x": 2}
# Deep merge dictionaries
base = {"a": {"b": 1}, "c": 2}
update = {"a": {"d": 3}, "e": 4}
merged = merge(base, update)
# {"a": {"b": 1, "d": 3}, "c": 2, "e": 4}
# Get values from nested dictionaries
data = {"user": {"profile": {"name": "Alice", "age": 30}}}
name = get_deep(data, "name") # "Alice" (suffix match)
age = get_deep(data, "user.profile.age") # 30 (exact match)
missing = get_deep(data, "missing", "default") # "default"
# Set values in nested dictionaries
data = {"a": 1}
result = set_deep(data, "user.name", "Bob")
# {"a": 1, "user": {"name": "Bob"}}
API
flatten_dict(data: dict) -> dict
Flatten nested dictionary into single-level with dot notation keys.
unflatten_dict(data: dict) -> dict
Convert flattened dictionary back to nested structure.
merge(data: dict, update: dict) -> dict
Deep merge two dictionaries. Values from update take precedence.
get_deep(data: dict, key: str, default=None) -> Any
Get value from nested dictionary using dot notation or suffix matching.
set_deep(data: dict, key: str, value: Any) -> dict
Set value in nested dictionary using dot notation. Returns new dictionary.
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
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 dictpress-0.3.0.tar.gz.
File metadata
- Download URL: dictpress-0.3.0.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.13 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7a509d89280161f38443fbc8403efd3c5a0082e3f4c45b55a291f8f0f69d51b
|
|
| MD5 |
f9feb8f8a78a228b2b0f802303dc9fea
|
|
| BLAKE2b-256 |
2237ebefee70f8716379f2c239ba78f0cba8af9b16745abedfb44c9401b80023
|
File details
Details for the file dictpress-0.3.0-py3-none-any.whl.
File metadata
- Download URL: dictpress-0.3.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.11.13 Darwin/24.5.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5dbe431669a510e73c7e097e700a312a2f8b0d3aceb6e622e1e725b46eced0b8
|
|
| MD5 |
07f3647fd8938a61286828012a5e0960
|
|
| BLAKE2b-256 |
e2db6b78eb04fd85031023329c1c24f3fa2040cc411d9a2303d5b4058c78f9fc
|