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

<pre><code>def foo():
    """This function does nothing."""
    pass
</code></pre>

<p>But what about a module? How can I document what a <em>file.py</em> does?</p>

[{'answer_id': 44094, 'author': 'David Locke', 'author_id': 1447, 'author_profile': 'https://Stackoverflow.com/users/1447', 'pm_score': 2, 'selected': False, 'text': "<p>It's easy, you just add a docstring at the top of the module.</p>\n"}, {'answer_id': 44095, 'author': 'Grégoire Cachet', 'author_id': 1044, 'author_profile': 'https://Stackoverflow.com/users/1044', 'pm_score': 7, 'selected': True, 'text': '<p>For the packages, you can document it in <code>__init__.py</code>.\nFor the modules, you can add a docstring simply in the module file.</p>\n\n<p>All the information is here: <a href="http://www.python.org/dev/peps/pep-0257/" rel="noreferrer">http://www.python.org/dev/peps/pep-0257/</a></p>\n'}, {'answer_id': 44098, 'author': 'Chris Upchurch', 'author_id': 2600, 'author_profile': 'https://Stackoverflow.com/users/2600', 'pm_score': 3, 'selected': False, 'text': '<p>You do it the exact same way.  Put a string in as the first statement in the module.</p>\n'}, {'answer_id': 23450896, 'author': 'Brad Koch', 'author_id': 425313, 'author_profile': 'https://Stackoverflow.com/users/425313', 'pm_score': 7, 'selected': False, 'text': '<p>Add your docstring as the <a href="http://www.python.org/dev/peps/pep-0257/" rel="noreferrer">first statement in the module</a>.</p>\n\n<pre><code>"""\nYour module\'s verbose yet thorough docstring.\n"""\n\nimport foo\n\n# ...\n</code></pre>\n\n<p>For packages, you can add your docstring to <code>__init__.py</code>.</p>\n'}, {'answer_id': 41913969, 'author': 'Vlad Bezden', 'author_id': 30038, 'author_profile': 'https://Stackoverflow.com/users/30038', 'pm_score': 5, 'selected': False, 'text': '<p>Here is an <a href="http://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html" rel="noreferrer">Example Google Style Python Docstrings</a> 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.</p>\n\n<pre><code>"""Example Google style docstrings.\n\nThis module demonstrates documentation as specified by the `Google\nPython Style Guide`_. Docstrings may extend over multiple lines.\nSections are created with a section header and a colon followed by a\nblock of indented text.\n\nExample:\n    Examples can be given using either the ``Example`` or ``Examples``\n    sections. Sections support any reStructuredText formatting, including\n    literal blocks::\n\n        $ python example_google.py\n\nSection breaks are created by resuming unindented text. Section breaks\nare also implicitly created anytime a new section starts.\n\nAttributes:\n    module_level_variable1 (int): Module level variables may be documented in\n        either the ``Attributes`` section of the module docstring, or in an\n        inline docstring immediately following the variable.\n\n        Either form is acceptable, but the two should not be mixed. Choose\n        one convention to document module level variables and be consistent\n        with it.\n\nTodo:\n    * For module TODOs\n    * You have to also use ``sphinx.ext.todo`` extension\n\n.. _Google Python Style Guide:   \nhttp://google.github.io/styleguide/pyguide.html\n\n"""\n\nmodule_level_variable1 = 12345\n\ndef my_function():   \n    pass \n... \n...\n</code></pre>\n'}, {'answer_id': 57529785, 'author': 'Kermit', 'author_id': 5739514, 'author_profile': 'https://Stackoverflow.com/users/5739514', 'pm_score': 2, 'selected': False, 'text': '<p><strong>For PyPI Packages:</strong></p>\n\n<p>If you add doc strings like this in your <strong>__init__.py</strong> file as seen below</p>\n\n<pre><code>"""\nPlease refer to the documentation provided in the README.md,\nwhich can be found at gorpyter\'s PyPI URL: https://pypi.org/project/gorpyter/\n"""\n\n# &lt;IMPORT_DEPENDENCIES&gt;\n\ndef setup():\n    """Verify your Python and R dependencies."""\n</code></pre>\n\n<p>Then you will receive this in everyday usage of the help function.</p>\n\n<p><code>help(&lt;YOUR_PACKAGE&gt;)</code></p>\n\n<pre><code>DESCRIPTION\n    Please refer to the documentation provided in the README.md,\n    which can be found at gorpyter\'s PyPI URL: https://pypi.org/project/gorpyter/\n\n\nFUNCTIONS\n    setup()\n        Verify your Python and R dependencies.\n</code></pre>\n\n<p>Note, that my help <code>DESCRIPTION</code> is triggered by having that first docstring at the very top of the file.</p>\n'}]
['https://Stackoverflow.com/questions/44084', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1679/']