Skip to main content

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

Project description

easydotdict

Make nested dictionaries effortless — dot-notation access, safe missing-key handling, auto-vivification, deep path operations, and pretty-printing. Pure Python, no dependencies.

from easydotdict import dotdict

d = dotdict({'user': {'profile': {'name': 'Alice'}}})
print(d.user.profile.name)       # Alice
print(d['user'].profile.name)    # same
print(d.user.email)              # None (safe, no error)

d.name = 'Alice'
d.name.character = 5  # auto-converts scalar -> nested: {'Alice': {'character': 5}}

d.config.database.host = 'localhost'  # auto-creates path
d.put('server.port', 8080)            # or use path string
print(d.dig('user.name'))             # Alice (deep path getter)

flat = d.flatten()                    # {'user.profile.name': 'Alice', ...}
restored = dotdict.unflatten(flat)   # reverse

d.merge({'settings': {'debug': True}})  # deep merge
print(d)                                # indented JSON

Features

  • Dot notationd.user.profile.name instead of d['user']['profile']['name']
  • Dual access — dot and bracket notation work interchangeably
  • Safe accessd.missing returns None, no KeyError/AttributeError
  • Auto-vivificationd.a.b.c = value auto-creates intermediate structures
  • Scalar auto-conversiond.name = 'Alice'; d.name.character = 5 wraps scalar into {'Alice': {'character': 5}}
  • Deep path operationsdig, put, has, get with dot-separated strings
  • Cursors — lightweight views into nested paths that mutate the original via cursor(path)
  • Diff & Patch — compare two dotdicts with diff(), apply changes with patch()
  • Batch operationsset_many({path: value}) and delete(*paths) for bulk work
  • Searchfind(name) returns all dot-paths matching a key name
  • Type validationexpect(schema) validates types at runtime
  • Change trackingon_change(path, cb) fires callbacks on mutation
  • Freezefreeze() / unfreeze() prevents further modification
  • Flatten / Unflatten — recursive flatten and restore with flatten() and unflatten()
  • Deep mergeupdate() and merge() merge recursively, preserving existing keys
  • Cloneclone() returns a deep independent copy
  • Empty checkis_empty() checks if the dict has no keys
  • Auto-conversion — nested dicts and lists containing dicts are wrapped automatically
  • Pretty-printprint(d) outputs indented JSON
  • Comparisons — scalars support <, >, <=, >= comparisons
  • f-string ready — format specs like {d.name:>10} delegate to the underlying value
  • to_dict() — recursively converts back to plain dicts and lists
  • Decorators@dotdictify, @defaults, @expect_schema, @freeze
  • Pure Python — standard library only, Python 3.8+

Install

pip install easydotdict

Documentation

See docs.md for full API reference, edge cases, and 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.1.tar.gz (9.1 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.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for easydotdict-1.1.1.tar.gz
Algorithm Hash digest
SHA256 0b8a09fd1d82f4616c284be986781470589fe168d9ee3bb5e195101ed589a583
MD5 e70422aa7220f46df7acd9775de7a8a1
BLAKE2b-256 8f51e189da69c1257c937e4fa6c911aaf277fc94183e0be930c3f6696a88b3f6

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for easydotdict-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f694747d7c16311f88c44d49e5b9a714b994aa202e58d0b7215e811745a5241f
MD5 9c4abf50827a8d727bf8f27c0dce2f28
BLAKE2b-256 425c2412a5cf17c112e0e2887eb50d729d89624c8afae92350fa393d26ec30cf

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