Python – How to document a module in Python

documentationpythonpython-module

That's it. If you want to document a function or a class, you put a string just after the definition. For instance:

def foo():
    """This function does nothing."""
    pass

But what about a module? How can I document what a file.py does?

Best Solution

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.