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:
api_response.py— consume a JSON API endpointapp_config.py— load, edit, and persist application configurationproduct_catalog.py— enrich GitHub repository dataconfig_manager.py— validate, watch, freeze, and bulk-override settingsdata_migration.py— diff, patch, find, and validate between data versionsgithub_stars.py— analyse repository metadata with find, diff, cursor, and expect
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)
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7160ed4ac6781a453aa400101835ee6b8305b0316a751e98b6f5e82b87c34260
|
|
| MD5 |
c8742aee9bae013b490c0ae4cb5ff16e
|
|
| BLAKE2b-256 |
78683a334799dbac213eb6287792bc82bf955e74a26332647e3196ad10178576
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca7e663d63562fff6493c8039e4afddefdcc45929934bce27616c7150fb67632
|
|
| MD5 |
7850ad7caeb6545432aba52e2ffb6339
|
|
| BLAKE2b-256 |
c9c843ce5610ca7f3d480d39cdd1816454fca99a7b73ccfe826a8e04c4a118cc
|