EasyDict for Python Dictionaries

1.13 · active · verified Fri Apr 10

EasyDict is a Python library that enables accessing dictionary values as attributes, providing a JavaScript-like dot notation for Python dictionaries. It works recursively for nested structures, making dictionary manipulation more convenient and readable. The current version is 1.13, and the library receives updates periodically, with several releases each year to address bugs and introduce minor enhancements.

Warnings

Install

Imports

Quickstart

Demonstrates creating an EasyDict from a Python dictionary, accessing nested values with dot notation, modifying attributes, and showing that it retains dictionary-like behavior.

from easydict import EasyDict

# Create an EasyDict from a dictionary
data = EasyDict({
    'settings': {
        'debug': True,
        'api_key': 'abc123xyz'
    },
    'users': [
        {'id': 1, 'name': 'Alice'},
        {'id': 2, 'name': 'Bob'}
    ]
})

# Access values using dot notation
print(f"Debug mode: {data.settings.debug}")
print(f"API Key: {data.settings.api_key}")
print(f"First user's name: {data.users[0].name}")

# Set new attributes or modify existing ones
data.settings.debug = False
data.new_feature = {'enabled': True}
print(f"New debug mode: {data.settings.debug}")
print(f"New feature enabled: {data.new_feature.enabled}")

# EasyDict still behaves like a dict
print(f"All keys: {list(data.keys())}")

view raw JSON →