Skip to content
Back to top
View this page

# 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`, and `autoexception` respectively. `autodoc_inherit_docstrings` does not currently work.

.. autoapifunction::
.. autoapidata::
.. autoapimethod::
.. autoapiattribute::

  Equivalent to `autofunction`, `autodata`, `automethod`, and `autoattribute` respectively.

## Inheritance Diagrams

.. autoapi-inheritance-diagram::

  This directive uses the `sphinx.ext.inheritance_diagram` extension 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_diagram` makes use of the `sphinx.ext.graphviz` extension, and therefore it requires Graphviz to be installed.

  The directive can be configured using the same options as `sphinx.ext.inheritance_diagram`.