How to produce documentation for Python functions?

Information about a function or documentation is put in docstrings in a function. The following are the guidelines to be followed while writing the docstrings.

The first line should always be a short, concise summary of the object’s purpose. For brevity, it should not explicitly state the object’s name or type.  This line should begin with a capital letter and end with a period.

If there are more lines in the documentation string, the second line should be blank, visually separating the summary from the rest of the description


Sphinx is the most popular Python documentation tool. It converts reStructuredText markup language into a range of output formats including HTML, LaTeX (for printable PDF versions), manual pages, and plain text.

When run, Sphinx will import your code and using Python’s introspection features it will extract all function, method and class signatures. It will also extract the accompanying docstrings, and compile it all into well-structured and easily readable documentation for your project.