Registry / serialization / attrdict

attrdict

JSON →
library2.0.1pypypi✓ verified 23d ago

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.

pip install attrdict
INSTALL
IMPORT
SIG · ATTRDICT
A
attrdict
serializationpythonv2.0.1
Install
1.6s avg
Import
10ms
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.0.1 · 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.002s · 17.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.002s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

AttrDict
from attrdict import AttrDict
from attrdict import AttrDict

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']}")
Debug
Known issues
breakingThe `attrdict` library is incompatible with Python 3.10 and newer versions. It relies on `from collections import Mapping`, which was removed in Python 3.10. Attempting to install or run `attrdict` on Python 3.10+ will result in an `ImportError`.
fix
Consider using alternative libraries like `addict` or implementing similar functionality with `types.SimpleNamespace` for Python 3.10+ environments. The project is unmaintained.
affects: >=3.10
deprecatedThe `attrdict` project is no longer actively maintained. Its GitHub repository was archived in February 2019, and it has not received updates since then. It is not recommended for new projects.
fix
For new projects, evaluate actively maintained alternatives like `addict` or `pydantic` for configuration management.
affects: all
gotchaWhen accessing nested dictionaries via attribute access (e.g., `attr.foo.bar`), `AttrDict` recursively converts internal dictionaries to `AttrDict` (or `AttrMap`) instances. Crucially, non-string sequence types (like lists) are *automatically converted to tuples* by default when accessed as an attribute.
fix
Be aware of this implicit type conversion. If you need to retain lists, consider using `AttrMap` and setting `sequence_type=None` or accessing via item notation (`attr['foo']['bar']`).
affects: all
gotchaThe `copy()` method of an `AttrDict` instance returns a standard Python `dict`, not another `AttrDict` instance.
fix
If you require a shallow copy that remains an `AttrDict`, you must explicitly convert the result: `new_attrdict = AttrDict(old_attrdict.copy())`.
affects: all
gotchaUnlike a standard `dict`, `AttrDict` does not clone the input dictionary upon creation. It uses the same dictionary instance internally. Modifying the original dictionary after creating an `AttrDict` from it will affect the `AttrDict` instance.
fix
If you need a decoupled instance, pass a copy of your dictionary: `settings = AttrDict(data.copy())`.
affects: all
Upgrade
Version history
2.0.1latest on PyPI · released Feb 1, 2019
Audit
Dependencies

No dependency data recorded yet.

Agent activity
43 hits · last 30 days
node
34
OpenAI (training)
1
Resources