Skip to main content

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.

Metadata

Release files for dictpress 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dictpress 0.3.0
File Size Uploaded
dictpress-0.3.0.tar.gz 3.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for dictpress 0.3.0
File Interpreter ABI Platform
dictpress-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / dictpress-0.3.0.tar.gz

Download URL dictpress-0.3.0.tar.gz
Size 3.3 kB
Tags Source
SHA-256 checksum
How to use checksums
c7a509d89280161f38443fbc8403efd3c5a0082e3f4c45b55a291f8f0f69d51b
BLAKE2b-256 checksum
How to use checksums
2237ebefee70f8716379f2c239ba78f0cba8af9b16745abedfb44c9401b80023
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.11.13 Darwin/24.5.0

Release files / dictpress-0.3.0-py3-none-any.whl

Download URL dictpress-0.3.0-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5dbe431669a510e73c7e097e700a312a2f8b0d3aceb6e622e1e725b46eced0b8
BLAKE2b-256 checksum
How to use checksums
e2db6b78eb04fd85031023329c1c24f3fa2040cc411d9a2303d5b4058c78f9fc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.11.13 Darwin/24.5.0

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page