Skip to main content

Effortless nested dictionary access — dot notation, safe missing keys, auto-vivification, and more

Project description

easydotdict

Navigate nested dictionaries with the simplicity of attribute access.
Zero dependencies. Python 3.8+.

from easydotdict import dotdict

d = dotdict({"user": {"profile": {"name": "Alice"}}})

# Read deeply with dot notation
print(d.user.profile.name)   # Alice
print(d["user"].profile.name)  # same, dual access

# Safe missing-key access — no exceptions
print(d.user.email)          # None

# Auto-create nested paths on assignment
d.config.database.host = "localhost"

# Scalar auto-conversion — string becomes a key
d.name = "Alice"
d.name.character = 5  # {"name": {"Alice": {"character": 5}}}

# Deep path string methods
d.put("server.port", 8080)
print(d.dig("user.name"))    # Alice

# Compare, diff, and migrate
v1 = dotdict({"app": {"debug": True}})
v2 = dotdict({"app": {"debug": False, "version": "2.0"}})
changes = v1.diff(v2)
v1.patch(changes)            # v1 now matches v2

# Recursive flatten and restore
flat = d.flatten()
restored = dotdict.unflatten(flat)

# Deep merge with key preservation
d.merge({"settings": {"theme": "dark"}})

# Pretty-printed JSON output
print(d)

Features

Category Capabilities
Access Dot notation (d.user.name), bracket notation (d["user"]), dual interchangeability
Safety Missing keys return None — no KeyError or AttributeError
Auto-vivification d.a.b.c = value creates intermediate structures automatically
Scalar conversion d.name = "Alice"; d.name.x = 1 promotes scalars to nested dicts
Deep paths dig(), get(), put(), has() with dot-separated strings; handles list indices (users.0.name)
Flatten / Unflatten Recursive flatten to dot-keys and restoration via unflatten()
Deep merge update() and merge() merge recursively, preserving existing keys
Diff & Patch diff(other) produces {path: {"from": ..., "to": ...}}; patch() applies changes
Batch operations set_many({path: value}) and delete(*paths) for bulk mutations
Search find(name) locates all dot-paths matching a key name anywhere in the tree
Cursor Lightweight views into nested paths — mutations affect the original
Type validation expect(schema) validates types at runtime; @expect_schema for functions
Change tracking on_change(path, cb) fires callbacks on mutation
Freeze freeze() / unfreeze() enforces immutability; @freeze for return values
Decorators @dotdictify converts arguments, @defaults supplies fallbacks
Comparisons Scalars support <, >, <=, >= and f-string formatting
Serialisation to_dict() unwraps to plain dict / list; pretty-printed JSON via print()
Compatibility Full dict subclass — keys(), items(), pop(), len(), in, etc. all work

Install

pip install easydotdict

Documentation

Full API reference, edge case table, and decorator guide: docs.md

Real-world examples:

License

MIT

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

easydotdict-1.1.3.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

easydotdict-1.1.3-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file easydotdict-1.1.3.tar.gz.

File metadata

  • Download URL: easydotdict-1.1.3.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for easydotdict-1.1.3.tar.gz
Algorithm Hash digest
SHA256 7160ed4ac6781a453aa400101835ee6b8305b0316a751e98b6f5e82b87c34260
MD5 c8742aee9bae013b490c0ae4cb5ff16e
BLAKE2b-256 78683a334799dbac213eb6287792bc82bf955e74a26332647e3196ad10178576

See more details on using hashes here.

File details

Details for the file easydotdict-1.1.3-py3-none-any.whl.

File metadata

  • Download URL: easydotdict-1.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for easydotdict-1.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ca7e663d63562fff6493c8039e4afddefdcc45929934bce27616c7150fb67632
MD5 7850ad7caeb6545432aba52e2ffb6339
BLAKE2b-256 c9c843ce5610ca7f3d480d39cdd1816454fca99a7b73ccfe826a8e04c4a118cc

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