DottedDict

raw JSON →
1.1.3 verified Fri May 01 auth: no python

DottedDict is a dict subclass that allows accessing nested keys using dot notation (e.g., d.key.subkey). Currently at version 1.1.3. Release cadence is irregular; last update was in 2020.

pip install dotted-dict
error KeyError: 'key' when trying to set d.new.key = 'value'
cause DottedDict does not auto-create intermediate keys on dot assignment.
fix
Set using standard dict assignment: d['new'] = DottedDict({'key': 'value'})
error AttributeError: 'DottedDict' object has no attribute 'items'
cause Accessing .items() on the DottedDict itself works but on nested ones? Actually it doesn't - nested DottedDict does have items method, but the error may occur if the nested value is not a DottedDict.
fix
Ensure nested values are DottedDict or use dict() conversion: dict(d['inner']).items()
gotcha DottedDict does not support dot notation assignment for creating new nested keys (e.g., d.new.key = 'value' will raise KeyError because intermediate keys are not auto-created).
fix Use d['new']['key'] = 'value' or pre-initialize the nested structure.
gotcha DottedDict overrides __getattr__ to mimic dict keys, so attributes like d.keys, d.items, d.values are lost. Use d.keys() only on the DottedDict itself; nested DottedDicts also override these.
fix Access these methods via d.keys() (works on the object) but be aware that nested DottedDicts also override them; use dict(d['inner']).keys() if needed.
gotcha DottedDict does not convert non-dict values to DottedDict. Only nested dicts are converted. Lists of dicts remain plain dicts.
fix Use DottedDict with nested structures; for lists, you must manually convert each element.

Creates a DottedDict from a nested dict and accesses nested keys with dot notation.

from dotted_dict import DottedDict

d = DottedDict({'a': {'b': 'value'}})
print(d.a.b)  # output: value