Registry / serialization / attributes-doc

attributes-doc

JSON →
library0.5.0pypypi✓ verified 23d ago

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.

pip install attributes-doc
INSTALL
IMPORT
SIG · ATTRIBUTES-DOC
A
attributes-doc
serializationpythonv0.5.0
Install
1.6s avg
Import
34ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.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.036s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.032s · 18MB
16MB installed
● package 16MB
Code
Verified usage

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

attributes_doc
from attributes_doc import attributes_doc
get_attributes_doc
from attributes_doc import get_attributes_doc
enum_doc
from attributes_doc import enum_doc
get_doc
from attributes_doc import get_doc

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.

from attributes_doc import attributes_doc, enum_doc, get_doc from enum import Enum @attributes_doc class MyClass: foo = 1 """This is the docstring for foo.""" bar = 'hello' """Docstring for bar.""" print(MyClass.__doc_foo__) # Access docstring via a special attribute print(get_doc(MyClass, 'bar')) # Use get_doc helper @enum_doc class MyEnum(Enum): VALUE_A = 1 """Description for value A.""" VALUE_B = 2 """Description for value B.""" print(MyEnum.VALUE_A.__doc__) # Access docstring directly on enum value print(get_doc(MyEnum, 'VALUE_B')) # Use get_doc helper
Debug
Known issues
breakingVersion 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).
fix
Upgrade to Python 3.8+ or use `attributes-doc<0.4.0`.
affects: >=0.4.0
gotchaPython 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')`.
fix
Access attribute docstrings using `MyClass.__doc_attribute__`, `MyEnum.VALUE.__doc__`, or `get_doc(Class, 'attribute_name')`.
affects: All
gotchaThe 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.
fix
Understand that the library's scope is focused solely on adding and retrieving docstrings for class attributes and enum members.
affects: All
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'attributes_doc'
The 'attributes-doc' package is not installed in the Python environment.
fix
Install the package using pip: 'pip install attributes-doc'.
AttributeError: module 'attributes_doc' has no attribute 'attributes_doc'
Attempting to access a non-existent attribute in the 'attributes_doc' module.
fix
Ensure the correct usage of the module's functions as per the documentation.
ImportError: cannot import name 'attributes_doc' from 'attributes_doc'
Incorrect import statement due to module name shadowing or misnaming.
fix
Verify the module's structure and use the correct import statement.
AttributeError: 'SomeClass' object has no attribute '__attributes_doc__'
The `get_attributes_doc` or `get_doc` function was called on a class or instance that was not decorated with `@attributes_doc` or `@enum_doc`, meaning the internal docstring mapping was never created.
fix
Apply the `@attributes_doc` decorator to the class definition to enable attribute docstring support:

```python
from attributes_doc import attributes_doc, get_attributes_doc

@attributes_doc
class MyClass:
    FIELD: str = ""
```
TypeError: 'docstring' object is not callable
This error can occur if a developer mistakenly tries to access an attribute docstring as if it were a method, or if they're trying to assign a value to `__doc__` directly on an attribute which is not supported by standard Python.
fix
Attribute docstrings are retrieved using the provided `get_doc` function, not by directly calling the attribute or its `__doc__`.

```python
from attributes_doc import attributes_doc, get_doc

@attributes_doc
class MyClass:
    FIELD: str = "The field's documentation."

print(get_doc(MyClass, 'FIELD'))
```
Upgrade
Version history
0.5.0latest on PyPI · released Aug 18, 2026
Audit
Dependencies
pythonrequiredRequires Python 3.8 or higher.
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources
attributes-doc — pip install attributes-doc · libregistry