class-doc
raw JSON → 0.2.6 verified Mon Apr 27 auth: no python
A library to extract attributes docstrings defined in various ways, such as class attributes, NamedTuple fields, or dataclass fields. Current version 0.2.6, released 2025-01-29, maintained infrequently.
pip install class-doc Common errors
error AttributeError: module 'class_doc' has no attribute 'attr_doc' ↓
cause Incorrect import path: using 'import class_doc' instead of 'from class_doc import attr_doc'.
fix
Use 'from class_doc import attr_doc'.
error TypeError: attr_doc() got an unexpected keyword argument 'include_inherited' ↓
cause The parameter was added in a later version; using an older version of class-doc (pre-0.2.0).
fix
Upgrade to latest version: pip install class-doc --upgrade
Warnings
gotcha Attribute docstrings must be on the same line as the type annotation and value, after the comma or default value. They are not standard docstrings but trailing comments. ↓
fix Ensure each attribute is defined as 'name: type = default # docstring'. The comment must be at the end of the line.
gotcha Only works with type-annotated attributes (PEP 526). Attributes without type hints or with only a comment before the variable will be ignored. ↓
fix Add type annotations to all attributes you want to extract docstrings from.
deprecated The library may not be actively maintained; last release was in 2025. No known deprecations. ↓
fix Consider alternative libraries like 'docstring_parser' or using 'typing.get_type_hints' with comments manually.
Imports
- attr_doc wrong
from class_doc import attr_doccorrectfrom class_doc import attr_doc
Quickstart
from class_doc import attr_doc
class Employee:
name: str = 'default' # Employee name
age: int = 0 # Age in years
# Extract docstrings
docs = attr_doc(Employee)
print(docs)
# {'name': 'Employee name', 'age': 'Age in years'}