Directives¶
Autodoc-Style Directives¶
You can opt to write API documentation yourself using autodoc style directives. These directives work similarly to autodoc, but docstrings are retrieved through static analysis instead of through imports.
See also
When transitioning to autodoc-style documentation,
you may want to turn the autoapi_generate_api_docs
option off so that automatic API documentation is no longer generated.
To use these directives you will need to enable the autodoc extension
in your Sphinx project’s conf.py:
extensions = ['sphinx.ext.autodoc', 'autoapi.extension']
For Python, all directives have an autodoc equivalent and accept the same options. The following directives are available:
- .. autoapimodule::¶
- .. autoapiclass::¶
- .. autoapiexception::¶
Equivalent to
automodule,autoclass, andautoexceptionrespectively.autodoc_inherit_docstringsdoes not currently work.
- .. autoapifunction::¶
- .. autoapidata::¶
- .. autoapimethod::¶
- .. autoapiattribute::¶
Equivalent to
autofunction,autodata,automethod, andautoattributerespectively.
Inheritance Diagrams¶
- .. autoapi-inheritance-diagram::¶
This directive uses the
sphinx.ext.inheritance_diagramextension to create inheritance diagrams for classes.For example:
digraph inheritance7d854a9910 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "PythonModule" [URL="templates.html#autoapi._objects.PythonModule",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="The representation of a module."]; "TopLevelPythonPythonMapper" -> "PythonModule" [arrowsize=0.5,style="setlinewidth(0.5)"]; "PythonObject" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="A class representing an entity from the parsed source code."]; "PythonPackage" [URL="templates.html#autoapi._objects.PythonPackage",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="The representation of a package."]; "TopLevelPythonPythonMapper" -> "PythonPackage" [arrowsize=0.5,style="setlinewidth(0.5)"]; "TopLevelPythonPythonMapper" [URL="templates.html#autoapi._objects.TopLevelPythonPythonMapper",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A common base class for modules and packages."]; "PythonObject" -> "TopLevelPythonPythonMapper" [arrowsize=0.5,style="setlinewidth(0.5)"]; }sphinx.ext.inheritance_diagrammakes use of thesphinx.ext.graphvizextension, and therefore it requires Graphviz to be installed.The directive can be configured using the same options as
sphinx.ext.inheritance_diagram.