Skip to main content

transform flat key-path dictionaries into nested structures with ease

Project description

nestify

nestify is a tiny utility that transforms flat dictionaries with path-like keys into proper nested structures.
Think of it as the inverse of flatten:

from nestify import nestify

data = {
    "a.b.c": 1,
    "a.d": 2,
    "x": 3
}

print(nestify(data))
# => {"a": {"b": {"c": 1}, "d": 2}, "x": 3}

✨ Features

  • Custom separators
    Not limited to dots (.) — use /, :, ::, or any string as a separator.

  • Conflict resolution policies
    Choose how to handle conflicts:

    • forbid_mixed: strict mode, disallow mixing dict/non-dict (default).
    • merge_dicts: merge dictionaries recursively, warn on key overlaps.
    • overwrite: always overwrite existing values, with a warning.
  • Recursive processing
    Values that are dictionaries themselves are also expanded.

  • Safe & predictable
    Warnings and errors make conflicts explicit, avoiding silent data corruption.

🔧 Usage Examples

Basic Expansion

from nestify import nestify

nestify({"a.b": 1, "a.c": 2})
# => {"a": {"b": 1, "c": 2}}

Custom Separator

from nestify import nestify

nestify({"root/child": 42}, separator="/")
# => {"root": {"child": 42}}

Conflict Resolution

from nestify import nestify

# Overwrite mode
nestify({"a.b": 1, "a.b": 2}, conflict_policy="overwrite")
# => {"a": {"b": 2}}

💡 Why nestify?

When working with configs, JSON/YAML, or flattened exports (from APIs, databases, etc.), you often get keys like "user.profile.name". nestify makes it effortless to convert them into proper nested dicts.

📦 Installation

pip install nestify

🧾 License

MIT License. See LICENSE for details.

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

nestify-0.0.1.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file nestify-0.0.1.tar.gz.

File metadata

  • Download URL: nestify-0.0.1.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for nestify-0.0.1.tar.gz
Algorithm Hash digest
SHA256 34374fdfac0f170a2ee4a8332e09eb263441e3a9ae6e8e2ef0b176b8ce819afd
MD5 17548611e4b8328efa8d85db523b3c17
BLAKE2b-256 77deb45ecb01caf306ef26cffcf56bdc5e7a7e450b881c918c6ace53284926b8

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