I have a Python project in PyCharm and I'd like to automatically generate API documentation (in the form of HTML) from my Python code and docstrings.
According to this page, there are a number of tools that generate Python API documentation:
The page additionally notes that the following tools "process documentation":
The PyCharm documentation says that DocUtils and Sphinx can be used to "produce the formatted API documentation". However, this seems to be incorrect, as their configuration indicates that those tools process only *.rst
files, not *.py
files.
My question is this: Can I use the DocUtils or Sphinx features of PyCharm to generate the API documentation?
Failing that, can I use any features of PyCharm to do this?
Failing that, are there any tools to do this that integrate well with PyCharm?
Place the caret somewhere within the function you want to document. Press Alt+Enter to show the available intention actions. PyCharm generates documentation comment stub according to docstring format, selected in the Python Integrated Tools page.
In the Docstrings section, set the Docstring format to 'reStructuredText' and make sure 'Analyze Python code in doctrings' is selected. If you type the triple quotes to start your docstring and then press Enter, PyCharm will automatically provide a number of relevant sphinx Info Fields for you.
I also stumbled on this problem in short:
My question is this: Can I use the DocUtils or Sphinx features of PyCharm to generate the API documentation?
No. However, you can use PyCharm to quickly view documentation ctrl+Q and it will be nicely formatted with links,tables etc.
Failing that, can I use any features of PyCharm to do this?
Not really, PyCharm can only insert documentation stub for functions and methods but it cannot do an api discovery to automatically comment everything it also cannot create rst documents stub.
Failing that, are there any tools to do this that integrate well with PyCharm?
Yes :) sphinx-apidoc it is a tool that will automatically create rst documents from your code. There is also less known autoapi
You just point to the root directory and voila it can even include members without doc string. It really just create a simple rst document using automodule syntax. After that you can just run sphinx task from PyCharm and you have a documentation of your code you can even use a theme like sphinx_rtd_theme
to make it look really nice.
Example:
sphinx-apidoc -o source/ ../
Assuming you created a doc folder inside you project, then cd doc
and used sphinx-quickstart
the above command goes up to parent directory to discover any source file and document them. The result is stored in <project>/doc/source
folder. Among other files there will be a modules.rst pulling all auto generated files together.
Then in your index.rst you add a line in .. toctree:: ... source/modules
EDIT
Recently I found a new tool to which I quickly switched seeing how easy it is to use pdoc3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With