{"id":4438,"library":"attributes-doc","title":"Attributes Doc","description":"attributes-doc is a Python library providing a hacky implementation of PEP 224 for attribute docstrings. It offers decorators (`attributes_doc`, `enum_doc`) to attach docstrings to class attributes and enum values, and functions (`get_attributes_doc`, `get_doc`) to retrieve them at runtime. The current version is 0.4.0, with a release cadence that has seen updates for Python version compatibility and new features like `enum_doc` in recent major versions.","status":"active","version":"0.4.0","language":"en","source_language":"en","source_url":"https://github.com/tkukushkin/attributes-doc","tags":["documentation","docstrings","attributes","PEP 224","metaprogramming","enums"],"install":[{"cmd":"pip install attributes-doc","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Requires Python 3.8 or higher.","package":"python","optional":false}],"imports":[{"symbol":"attributes_doc","correct":"from attributes_doc import attributes_doc"},{"symbol":"get_attributes_doc","correct":"from attributes_doc import get_attributes_doc"},{"symbol":"enum_doc","correct":"from attributes_doc import enum_doc"},{"symbol":"get_doc","correct":"from attributes_doc import get_doc"}],"quickstart":{"code":"from attributes_doc import attributes_doc, enum_doc, get_doc\nfrom enum import Enum\n\n@attributes_doc\nclass MyClass:\n    foo = 1\n    \"\"\"This is the docstring for foo.\"\"\"\n\n    bar = 'hello'\n    \"\"\"Docstring for bar.\"\"\"\n\nprint(MyClass.__doc_foo__) # Access docstring via a special attribute\nprint(get_doc(MyClass, 'bar')) # Use get_doc helper\n\n@enum_doc\nclass MyEnum(Enum):\n    VALUE_A = 1\n    \"\"\"Description for value A.\"\"\"\n\n    VALUE_B = 2\n    \"\"\"Description for value B.\"\"\"\n\nprint(MyEnum.VALUE_A.__doc__) # Access docstring directly on enum value\nprint(get_doc(MyEnum, 'VALUE_B')) # Use get_doc helper","lang":"python","description":"This example demonstrates how to use the `attributes_doc` decorator for regular classes and `enum_doc` for Enum classes. It also shows how to retrieve the attribute docstrings using both the generated `__doc_ATTRNAME__` attribute (for classes) or `__doc__` (for enum values) and the `get_doc` helper function."},"warnings":[{"fix":"Upgrade to Python 3.8+ or use `attributes-doc<0.4.0`.","message":"Version 0.4.0 dropped support for Python versions older than 3.8. Users on EOL Python versions will need to upgrade their Python interpreter or pin to an older version of `attributes-doc` (e.g., 0.3.0).","severity":"breaking","affected_versions":">=0.4.0"},{"fix":"Access attribute docstrings using `MyClass.__doc_attribute__`, `MyEnum.VALUE.__doc__`, or `get_doc(Class, 'attribute_name')`.","message":"Python class attributes do not natively support `__doc__` attributes directly like functions or classes do. `attributes-doc` uses a convention where it stores the docstring in `__doc_ATTRNAME__` (for regular class attributes) or directly on the `__doc__` of individual enum *values* (for `enum_doc`). Do not expect `MyClass.attribute.__doc__` to work directly; instead, use `MyClass.__doc_attribute__` or `get_doc(MyClass, 'attribute')`.","severity":"gotcha","affected_versions":"All"},{"fix":"Understand that the library's scope is focused solely on adding and retrieving docstrings for class attributes and enum members.","message":"The library name 'attributes-doc' is broad. This library specifically implements a 'hacky implementation of PEP 224' for Python *attribute docstrings*. It is not a general-purpose attribute validation, mutation, or metaclass utility (like 'characteristic' or 'traits'), nor is it related to Git attributes or HTML attributes.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}