AttrDict

2.0.1 · deprecated · verified Sun Apr 12

AttrDict is an MIT-licensed Python library (version 2.0.1) providing mapping objects that allow their elements to be accessed both as keys (like a standard dict) and as attributes. It aims to simplify the creation of hierarchical data structures, particularly useful for configuration objects. The project's last release was in 2019, and its GitHub repository was archived in the same year, indicating it is no longer actively maintained.

Warnings

Install

Imports

Quickstart

Initialize an `AttrDict` from a dictionary and access its elements using attribute-style notation. Demonstrates both valid access and the `AttributeError` for non-existent attributes.

from attrdict import AttrDict

# Create an AttrDict from a regular dictionary
data = {'server': {'host': 'localhost', 'port': 8000}, 'debug': True}
settings = AttrDict(data)

# Access elements using attribute notation
print(f"Host: {settings.server.host}")
print(f"Port: {settings.server.port}")

# Attribute access for non-existent keys raises AttributeError
try:
    print(settings.non_existent)
except AttributeError as e:
    print(f"Error accessing non_existent attribute: {e}")

# Item access (like dict) still works
print(f"Debug setting: {settings['debug']}")

view raw JSON →