{"id":4340,"library":"attrdict","title":"AttrDict","description":"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.","status":"deprecated","version":"2.0.1","language":"en","source_language":"en","source_url":"https://github.com/bcj/AttrDict","tags":["dictionary","attribute access","data structure","configuration","deprecated"],"install":[{"cmd":"pip install attrdict","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"AttrDict","correct":"from attrdict import AttrDict"},{"note":"An alternative MutableMapping that offers more control over recursive conversions and does not inherit directly from `dict`.","symbol":"AttrMap","correct":"from attrdict import AttrMap"},{"note":"Provides `defaultdict`-style automatic creation of attributes.","symbol":"AttrDefault","correct":"from attrdict import AttrDefault"}],"quickstart":{"code":"from attrdict import AttrDict\n\n# Create an AttrDict from a regular dictionary\ndata = {'server': {'host': 'localhost', 'port': 8000}, 'debug': True}\nsettings = AttrDict(data)\n\n# Access elements using attribute notation\nprint(f\"Host: {settings.server.host}\")\nprint(f\"Port: {settings.server.port}\")\n\n# Attribute access for non-existent keys raises AttributeError\ntry:\n    print(settings.non_existent)\nexcept AttributeError as e:\n    print(f\"Error accessing non_existent attribute: {e}\")\n\n# Item access (like dict) still works\nprint(f\"Debug setting: {settings['debug']}\")","lang":"python","description":"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."},"warnings":[{"fix":"Consider using alternative libraries like `addict` or implementing similar functionality with `types.SimpleNamespace` for Python 3.10+ environments. The project is unmaintained.","message":"The `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`.","severity":"breaking","affected_versions":">=3.10"},{"fix":"For new projects, evaluate actively maintained alternatives like `addict` or `pydantic` for configuration management.","message":"The `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.","severity":"deprecated","affected_versions":"all"},{"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']`).","message":"When 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.","severity":"gotcha","affected_versions":"all"},{"fix":"If you require a shallow copy that remains an `AttrDict`, you must explicitly convert the result: `new_attrdict = AttrDict(old_attrdict.copy())`.","message":"The `copy()` method of an `AttrDict` instance returns a standard Python `dict`, not another `AttrDict` instance.","severity":"gotcha","affected_versions":"all"},{"fix":"If you need a decoupled instance, pass a copy of your dictionary: `settings = AttrDict(data.copy())`.","message":"Unlike 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.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}