Ben Hoff Ben Hoff - 1 year ago 113
Python Question

Automatically create a toctree for auto doc classes in Sphinx

I'm looking to increase the documentation in one of my libraries. I've been using sphinx to help build the documentation and recently started exploring the autodoc extension.

It seems like in most professional documentation, each class documentation page has a list of all the documented methods with links at the top. Or, in other words, a toctree at the top with hyperlinks to each of the more in depth method documentation.

Is there a way to automatically create this toctree for each of the classes being documented with autodoc?

Answer Source

In your file for sphinx add 'sphinx.ext.autosummary' to your extensions, set autosummary_generate to True and set the autodoc_default_flags = ['members'].

I put the toctree in my index.rst

     :toctree: stubs


See this example for the settings

and this example for an example of the toctree.

Hope that helps!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download