How do I document a module in Python?

Viewed 61970

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?

6 Answers

You do it the exact same way. Put a string in as the first statement in the module.

It's easy, you just add a docstring at the top of the module.

For PyPI Packages:

If you add doc strings like this in your __init__.py file as seen below

"""
Please refer to the documentation provided in the README.md,
which can be found at gorpyter's PyPI URL: https://pypi.org/project/gorpyter/
"""

# <IMPORT_DEPENDENCIES>

def setup():
    """Verify your Python and R dependencies."""

Then you will receive this in everyday usage of the help function.

help(<YOUR_PACKAGE>)

DESCRIPTION
    Please refer to the documentation provided in the README.md,
    which can be found at gorpyter's PyPI URL: https://pypi.org/project/gorpyter/


FUNCTIONS
    setup()
        Verify your Python and R dependencies.

Note, that my help DESCRIPTION is triggered by having that first docstring at the very top of the file.

Related