AttributeDict

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

Simple dictionary subclass that exposes keys as attributes (e.g., obj.mykey instead of obj['mykey']). Requires Python 3.5+. Currently maintained with steady releases.

pip install attributedict
error ModuleNotFoundError: No module named 'attributedict'
cause Package not installed or import path wrong.
fix
Run 'pip install attributedict' and use 'from attributedict import AttributeDict'.
error AttributeError: 'AttributeDict' object has no attribute 'mykey'
cause Attempting to access a non-existent key via attribute.
fix
Use .get() to safely access: obj.get('mykey', default) or check existence with 'mykey' in obj.
error KeyError: 'mykey' when accessing via bracket
cause Standard dict bracket notation still raises KeyError for missing keys.
fix
Use .get() instead: obj.get('mykey', default).
gotcha AttributeDict stores keys as attributes, which may shadow built-in methods (e.g., if your key is 'keys' or 'items').
fix Avoid using keys that conflict with dict methods, or use standard dict access for those keys.
gotcha Nested dictionaries are only shallowly converted; nested dicts inside an AttributeDict remain standard dicts unless you explicitly wrap them.
fix Recursively convert with: AttributeDict(nested_dict) for each level, or use a helper function.
deprecated The library has not been updated since 2020; consider using more actively maintained alternatives like 'python-box' or 'attrdict' for newer Python versions.
fix Evaluate if the library meets your needs; if you need ongoing support, migrate to box or attrdict.

Basic usage showing attribute access, .get(), assignment, and dict representation.

from attributedict import AttributeDict

# Create an AttributeDict
addr = AttributeDict({'city': 'Oslo', 'zip': '0150'})
# Access keys as attributes
print(addr.city)  # Oslo
print(addr.get('zip'))  # '0150'
# Set new attribute
addr.country = 'Norway'
print(addr)  # {'city': 'Oslo', 'zip': '0150', 'country': 'Norway'}