Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dictpress-0.2.0.tar.gz (3.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dictpress-0.2.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file dictpress-0.2.0.tar.gz.

File metadata

  • Download URL: dictpress-0.2.0.tar.gz
  • Upload date:
  • Size: 3.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.11.13 Darwin/24.5.0

File hashes

Hashes for dictpress-0.2.0.tar.gz
Algorithm Hash digest
SHA256 fae0410432d81335398730f5dbe187ab80c550546faea2dad45267d0cbb5834b
MD5 181d96f9d881163512ed2a5606df161a
BLAKE2b-256 8a5d9f9cc4ea8c0a9db8144b6a7aca31e6a8033af59a650edb58201e8bd2ea20

See more details on using hashes here.

File details

Details for the file dictpress-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: dictpress-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 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

Hashes for dictpress-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f58926bc7d53e832b576b7e6ffdfacab036c7eb28fc29cdf6664c9ef49c23850
MD5 b24bd78588552d65b7123d82532edc46
BLAKE2b-256 a87b5483062160ee4ea6d6f537429d1ab4f4885e2fdd593b39fcf6dbe51b1fa0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page