How To Document Python Packages Using Sphinx
Solution 1:
Here is an outline:
- Document your package using docstrings in the sources.
- Use sphinx-quickstart to create a Sphinx project.
Run sphinx-apidoc to generate .rst sources set up for use with autodoc. More information here.
Using this command with the
-F
flag also creates a complete Sphinx project. If your API changes a lot, you may need to re-run this command several times.- Build the documentation using sphinx-build.
Notes:
Sphinx requires .rst files with directives like
automodule
orautoclass
in order to generate API documentation. It does not automatically extract anything from the Python sources without these files. This is different from how tools like Epydoc or Doxygen work. The differences are elaborated a bit more here: What is the relationship between docutils and Sphinx?.After you have run sphinx-apidoc, it may be necessary to adjust
sys.path
in conf.py for autodoc to find your modules.In order to avoid strange errors like in these questions, How should I solve the conflict of OptionParser and sphinx-build in a large project?, Is OptionParser in conflict with sphinx?, make sure that the code is properly structured, using
if __name__ == "__main__":
guards when needed.
Post a Comment for "How To Document Python Packages Using Sphinx"