22

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?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Ben Hoff
  • 1,058
  • 1
  • 11
  • 24
  • 1
    This might be of interest: http://stackoverflow.com/q/14606348/407651 – mzjn Jan 02 '16 at 08:15
  • @mzjn, that is of interest and I have it partially implemented. However, I am still not able to get a toctree at the top of the class documentation within the stub. – Ben Hoff Mar 06 '16 at 02:27
  • Oh, nvm I was confused. I got it to work! If you want to post an answer, I'll accept it. Otherwise I'll post one up for posterity. – Ben Hoff Mar 06 '16 at 20:30

1 Answers1

17

In your conf.py file for sphinx add

extensions = ['sphinx.ext.autosummary',]
# NOTE: Don't overwrite your old extension list! Just add to it!

autodoc_default_flags = ['members']
autosummary_generate = True

I put the toctree in my index.rst, and it looks like this:

.. autosummary::
     :toctree: stubs

     Class1
     Class2
     Class3

See this example for the conf.py settings

and this example for an example of the toctree.

Hope that helps!

Ben Hoff
  • 1,058
  • 1
  • 11
  • 24