How do I document a module in Python? How do I document a module in Python? python python

How do I document a module in Python?


Add your docstring as the first statement in the module.

"""Your module's verbose yet thorough docstring."""import foo# ...

For packages, you can add your docstring to __init__.py.


For the packages, you can document it in __init__.py.For the modules, you can add a docstring simply in the module file.

All the information is here: http://www.python.org/dev/peps/pep-0257/


Here is an Example Google Style Python Docstrings on how module can be documented. Basically there is an information about a module, how to execute it and information about module level variables and list of ToDo items.

"""Example Google style docstrings.This module demonstrates documentation as specified by the `GooglePython Style Guide`_. Docstrings may extend over multiple lines.Sections are created with a section header and a colon followed by ablock of indented text.Example:    Examples can be given using either the ``Example`` or ``Examples``    sections. Sections support any reStructuredText formatting, including    literal blocks::        $ python example_google.pySection breaks are created by resuming unindented text. Section breaksare also implicitly created anytime a new section starts.Attributes:    module_level_variable1 (int): Module level variables may be documented in        either the ``Attributes`` section of the module docstring, or in an        inline docstring immediately following the variable.        Either form is acceptable, but the two should not be mixed. Choose        one convention to document module level variables and be consistent        with it.Todo:    * For module TODOs    * You have to also use ``sphinx.ext.todo`` extension.. _Google Python Style Guide:   http://google.github.io/styleguide/pyguide.html"""module_level_variable1 = 12345def my_function():       pass ... ...