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?

3
  • 1
    This might be of interest: stackoverflow.com/q/14606348/407651 Commented Jan 2, 2016 at 8: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. Commented Mar 6, 2016 at 2: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. Commented Mar 6, 2016 at 20:30

1 Answer 1

18

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!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.