Registry / serialization / addict

addict

JSON →
library2.4.0pypypi✓ verified 8d ago

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.

pip install addict
INSTALL
IMPORT
SIG · ADDICT
A
addict
serializationpythonv2.4.0
Install
1.5s avg
Import
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.4.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.5s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Dict
from addict import Dict

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)
Debug
Known issues
breakingIn version 2.0.0, accessing a non-existent key via attribute (e.g., `my_dict.non_existent_key`) no longer automatically creates an empty `Dict` and adds it to the parent. It now returns an empty `Dict` but *does not* modify the original `my_dict`. To add a key, you must assign a value (e.g., `my_dict.new_key = {}`).
fix
Explicitly assign an empty `Dict` or any value to the new key to ensure it's added, e.g., `my_dict.new_key = Dict()` or `my_dict.new_key = {}`.
affects: >=2.0.0
gotchaKeys that are not valid Python identifiers (e.g., integers, keys with spaces or special characters) cannot be accessed or set using attribute (dot) syntax. These must still be accessed using standard item (square bracket) syntax.
fix
Use `my_dict[2]` or `my_dict['key-with-hyphen']` instead of `my_dict.2` or `my_dict.key-with-hyphen` for non-string or non-identifier keys.
affects: all
gotchaWhen initializing a `Dict` with an iterable containing other container types (like a list of dictionaries), `addict` clones these values and converts nested dictionaries into `Dict` instances. However, if you later assign an existing container type via attribute or item syntax, `addict` generally maintains the reference to the original object, leading to different behavior than during initial construction.
fix
Be aware of whether you are initializing with a structure or later assigning references. If deep conversion is always desired, consider using `addict.Dict(your_data)` for initial setup or manually converting nested structures.
affects: all
gotchaThe `freeze()` method (introduced in v2.4.0) prevents the creation or retrieval of missing keys, raising a `KeyError` or `AttributeError` instead. This changes the default 'autovivification' behavior of `addict` and can lead to unexpected errors if not handled.
fix
Understand when `freeze()` is active. If you need to add or access potentially missing keys on a frozen `Dict`, call `my_dict.unfreeze()` first, or check for key existence before access.
affects: >=2.4.0
Errors
Common errors & fixes
AttributeError: 'dict' object has no attribute 'id'
Attempting to access dictionary keys using dot notation instead of bracket notation.
fix
Use bracket notation to access dictionary keys, e.g., `task['id']` instead of `task.id`.
AttributeError: 'dict' object has no attribute 'add'
Trying to use the `add` method on a dictionary, which is not available.
fix
Use the appropriate method for adding items to a dictionary, such as `dict[key] = value`.
AttributeError: 'dict' object has no attribute 'iteritems'
Using the `iteritems()` method, which was removed in Python 3.x.
fix
Replace `iteritems()` with `items()` to iterate over dictionary items in Python 3.x.
AttributeError: 'dict' object has no attribute 'append'
Attempting to use the `append` method on a dictionary, which is not supported.
fix
To add a new key-value pair to a dictionary, use `dict[key] = value`.
AttributeError: 'dict' object has no attribute 'update'
Trying to use the `update` method on an object that is not a dictionary.
fix
Ensure the object is a dictionary before calling `update`, or convert it to a dictionary if necessary.
Upgrade
Version history
2.4.0latest on PyPI · released Nov 21, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
53 hits · last 30 days
node
46
Amazon
1
Resources
addict — pip install addict · libregistry