Sphinx extension for auto-generating API documentation for entire modules
npx @tessl/cli install tessl/pypi-sphinx-automodapi@0.20.0A Sphinx extension that automatically generates comprehensive API documentation for entire Python modules. Originally developed for the Astropy project, sphinx-automodapi eliminates the need for manual API documentation maintenance by automatically discovering and documenting all public module members, including their docstrings, function signatures, and inheritance relationships.
pip install sphinx-automodapiimport sphinx_automodapiFor configuring the extension in Sphinx conf.py:
extensions = [
'sphinx_automodapi.automodapi',
'sphinx_automodapi.smart_resolver',
# Other extensions...
]Add to your Sphinx conf.py:
extensions = ['sphinx_automodapi.automodapi']Then use directives in your reStructuredText files:
.. automodapi:: mypackage.mymoduleThis generates complete API documentation including:
sphinx-automodapi uses Sphinx's directive system to extend reStructuredText with new documentation directives. The extension integrates deeply with Sphinx's autodoc system and provides three core components:
The main documentation generation directives that form the heart of sphinx-automodapi's functionality. These directives automatically discover module contents and generate comprehensive documentation.
# automodapi directive - generates complete module documentation
# Usage: .. automodapi:: module.name
# automodsumm directive - generates summary tables
# Usage: .. automodsumm:: module.name
# automod-diagram directive - generates inheritance diagrams
# Usage: .. automod-diagram:: module.nameFunctions for discovering module objects, processing text, and handling autosummary integration. These utilities power the directive functionality and can be used programmatically.
def find_mod_objs(modname: str, onlylocals: bool | list = False, sort: bool = False) -> tuple[list[str], list[str], list[object]]
def cleanup_whitespace(text: str) -> str
def find_autosummary_in_lines_for_automodsumm(lines: list[str], module: str = None, filename: str = None) -> list[tuple]Sphinx configuration values that control the behavior of sphinx-automodapi directives, including inheritance diagram display, file organization, and processing options.
# Configuration values for conf.py
automodapi_inheritance_diagram: bool = True
automodapi_toctreedirnm: str = 'api'
automodapi_writereprocessed: bool = False
automodsumm_writereprocessed: bool = False
automodsumm_inherited_members: bool = False
automodsumm_included_members: list = ['__init__', '__call__']
automodsumm_properties_are_attributes: bool = TrueHandles the mapping between API locations (where users import from) and source locations (where code is defined), ensuring that cross-references work correctly in complex package hierarchies.
def process_docstring(app, what: str, name: str, obj, options, lines: list)
def missing_reference_handler(app, env, node, contnode)
def merge_mapping(app, env, docnames, env_other)Enhancements to Sphinx's autodoc functionality that improve attribute documentation for complex class hierarchies, metaclass properties, and dataclass fields.
def type_object_attrgetter(obj: type, attr: str, *defargs) -> object
def setup(app: Sphinx) -> dict[str, bool]# Sphinx application and environment types
from sphinx.application import Sphinx
from sphinx.environment import BuildEnvironment
# Docutils node types
from docutils.nodes import Node, Element
# Extension setup return type
SetupReturn = dict[str, bool] # {'parallel_read_safe': bool, 'parallel_write_safe': bool}