Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automatically generate Python API documentation in PyCharm [closed]

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:

  • autosummary
  • autodoc
  • pdoc
  • PyDoc
  • pydoctor
  • Doxygen

The page additionally notes that the following tools "process documentation":

  • DocUtils
  • Sphinx

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?

like image 830
dln385 Avatar asked Jun 27 '16 22:06

dln385


People also ask

How does PyCharm create documentation?

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.

How do I automatically add a docstring in PyCharm?

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.


1 Answers

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

like image 127
CodeSamurai777 Avatar answered Sep 28 '22 04:09

CodeSamurai777