Addict

2.4.0 · active · verified Thu Apr 09

Addict is a Python library that provides a dictionary subclass allowing items to be accessed and set using both attribute (dot notation) and item (square bracket) syntax. It simplifies working with deeply nested data structures. The library is currently at version 2.4.0 and demonstrates active maintenance with regular updates.

Warnings

Install

Imports

Quickstart

This example demonstrates how to create a `Dict` instance and populate nested keys using convenient attribute (dot) notation. It also shows accessing values and combining with standard dictionary item assignment.

from addict import Dict

# Create an Addict dictionary
body = Dict()

# Set nested values using dot notation
body.query.filtered.query.match.description = 'addictive'
body.query.filtered.filter.term.created_by = 'Mats'

print(body)
# Access values
print(body.query.filtered.query.match.description)

# Standard dict operations also work
body['metadata'] = {'source': 'API'}
print(body.metadata.source)

view raw JSON →