Think about somebody doing help(yourmodule) at the interactive interpreter's prompt β€” what do they want to know? (Other methods of extracting and displaying the information are roughly equivalent to help in terms of amount of information). So if you have in x.py:

"""This module does blah blah."""

class Blah(object):
  """This class does blah blah."""

then:

>>> import x; help(x)

shows:

Help on module x:

NAME
    x - This module does blah blah.

FILE
    /tmp/x.py

CLASSES
    __builtin__.object
        Blah

    class Blah(__builtin__.object)
     |  This class does blah blah.
     |  
     |  Data and other attributes defined here:
     |  
     |  __dict__ = <dictproxy object>
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__ = <attribute '__weakref__' of 'Blah' objects>
     |      list of weak references to the object (if defined)

As you see, the detailed information on the classes (and functions too, though I'm not showing one here) is already included from those components' docstrings; the module's own docstring should describe them very summarily (if at all) and rather concentrate on a concise summary of what the module as a whole can do for you, ideally with some doctested examples (just like functions and classes ideally should have doctested examples in their docstrings).

I don't see how metadata such as author name and copyright / license helps the module's user β€” it can rather go in comments, since it could help somebody considering whether or not to reuse or modify the module.

Answer from Alex Martelli on Stack Overflow
Top answer
1 of 2
264

Think about somebody doing help(yourmodule) at the interactive interpreter's prompt β€” what do they want to know? (Other methods of extracting and displaying the information are roughly equivalent to help in terms of amount of information). So if you have in x.py:

"""This module does blah blah."""

class Blah(object):
  """This class does blah blah."""

then:

>>> import x; help(x)

shows:

Help on module x:

NAME
    x - This module does blah blah.

FILE
    /tmp/x.py

CLASSES
    __builtin__.object
        Blah

    class Blah(__builtin__.object)
     |  This class does blah blah.
     |  
     |  Data and other attributes defined here:
     |  
     |  __dict__ = <dictproxy object>
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__ = <attribute '__weakref__' of 'Blah' objects>
     |      list of weak references to the object (if defined)

As you see, the detailed information on the classes (and functions too, though I'm not showing one here) is already included from those components' docstrings; the module's own docstring should describe them very summarily (if at all) and rather concentrate on a concise summary of what the module as a whole can do for you, ideally with some doctested examples (just like functions and classes ideally should have doctested examples in their docstrings).

I don't see how metadata such as author name and copyright / license helps the module's user β€” it can rather go in comments, since it could help somebody considering whether or not to reuse or modify the module.

2 of 2
68

To quote the specifications:

The docstring of a script (a stand-alone program) should be usable as its "usage" message, printed when the script is invoked with incorrect or missing arguments (or perhaps with a "-h" option, for "help"). Such a docstring should document the script's function and command line syntax, environment variables, and files. Usage messages can be fairly elaborate (several screens full) and should be sufficient for a new user to use the command properly, as well as a complete quick reference to all options and arguments for the sophisticated user.

The docstring for a module should generally list the classes, exceptions and functions (and any other objects) that are exported by the module, with a one-line summary of each. (These summaries generally give less detail than the summary line in the object's docstring.) The docstring for a package (i.e., the docstring of the package's __init__.py module) should also list the modules and subpackages exported by the package.

The docstring for a class should summarize its behavior and list the public methods and instance variables. If the class is intended to be subclassed, and has an additional interface for subclasses, this interface should be listed separately (in the docstring). The class constructor should be documented in the docstring for its __init__ method. Individual methods should be documented by their own docstring.

The docstring of a function or method is a phrase ending in a period. It prescribes the function or method's effect as a command ("Do this", "Return that"), not as a description; e.g. don't write "Returns the pathname ...". A multiline-docstring for a function or method should summarize its behavior and document its arguments, return value(s), side effects, exceptions raised, and restrictions on when it can be called (all if applicable). Optional arguments should be indicated. It should be documented whether keyword arguments are part of the interface.

🌐
Python
peps.python.org β€Ί pep-0257
PEP 257 – Docstring Conventions | peps.python.org
Such a docstring becomes the __doc__ special attribute of that object. All modules should normally have docstrings, and all functions and classes exported by a module should also have docstrings. Public methods (including the __init__ constructor) should also have docstrings.
🌐
DataCamp
datacamp.com β€Ί tutorial β€Ί docstrings-python
Python Docstrings Tutorial : Examples & Format for Pydoc, Numpy, Sphinx Doc Strings | DataCamp
February 14, 2025 - Python documentation string, commonly known as docstring, is a string literal, and it is used in the class, module, function, or method definition. Docstrings are accessible from the doc attribute (__doc__) for any of the Python objects and also with the built-in help() function.
🌐
Programiz
programiz.com β€Ί python-programming β€Ί docstrings
Python Docstrings (With Examples)
Python docstrings are the string literals that appear right after the definition of a function, method, class, or module.
🌐
Noirlab
datalab.noirlab.edu β€Ί docs β€Ί manual β€Ί DevGuide β€Ί DocumentingPythonAPIswithDocstrings β€Ί DocumentingPythonAPIswithDocstrings.html
3.2. Documenting Python APIs with Docstrings β€” Data Lab documentation
This module demonstrates documentation written according to LSST DM's guidelines for `Documenting Python APIs with Docstrings`_. Docstrings have well-specified sections. This paragraph is considered an `Extended Summary`_. Permitted sections are listed in `Numpydoc Sections in Docstrings`_.
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-docstrings
Python Docstrings - GeeksforGeeks
September 19, 2025 - Docstrings (Documentation Strings) are special strings used to document Python code. They provide a description of what a module, class, function or method does.
🌐
Real Python
realpython.com β€Ί documenting-python-code
Documenting Python Code: A Complete Guide – Real Python
July 17, 2026 - Module docstrings are similar to class docstrings. Instead of classes and class methods being documented, it’s now the module and any functions found within. Module docstrings are placed at the top of the file even before any imports.
🌐
Lsst
developer.lsst.io β€Ί v β€Ί DM-5063 β€Ί docs β€Ί py_docs.html
Documenting Python Code β€” LSST DM Developer Guide latest documentation
Python docstrings are special strings that form the __doc__ attributes attached to modules, classes, methods and functions.
Find elsewhere
🌐
Codesarray
codesarray.com β€Ί view β€Ί Docstrings-in-Python
Docstrings in Python - Codesarray
The module docstring provides an overview of the file, listing the functions it contains and briefly explaining their purposes. Description: High-level summary of the module's functionality.
🌐
Tutorialspoint
tutorialspoint.com β€Ί python β€Ί python_docstrings.htm
Python - Docstrings
In Python, docstrings are a way of documenting modules, classes, functions, and methods. They are written within triple quotes (""" """) and can span multiple lines. Docstrings serve as convenient way of associating documentation with Python code.
🌐
PythonForBeginners.com
pythonforbeginners.com β€Ί home β€Ί python docstrings
Python Docstrings - PythonForBeginners.com
August 28, 2020 - Python documentation strings (or docstrings) provide a convenient way of associating documentation with Python modules, functions, classes, and methods.
🌐
AskPython
askpython.com β€Ί python β€Ί python-docstring
Python Docstring - AskPython
February 16, 2023 - Python Docstring (Document String) is a string literal that is the first statement in a module, function, class, or method.
🌐
Mimo
mimo.org β€Ί glossary β€Ί python β€Ί docstrings
Python Docstrings: Syntax, Usage, and Examples
Attributes: make (str): The car's brand. model (str): The car's model. year (int): The year of manufacture. """ def __init__(self, make, model, year): self.make = make self.model = model self.year = year Β· Python modules should include a docstring at the beginning to explain their purpose.
🌐
Python Land
python.land β€Ί home β€Ί language deep dives β€Ί python docstring: documenting your code
Python Docstring: Documenting Your Code β€’ Python Land Tutorial
May 10, 2022 - A Python docstring is a string that occurs as the first statement in a module, function, class, or method definition.
🌐
Lsst
developer.lsst.io β€Ί v β€Ί DM-7919 β€Ί docs β€Ί py_docs.html
Documenting Python APIs β€” LSST DM Developer Guide latest documentation
Python docstrings are special strings that form the __doc__ attributes attached to modules, classes, methods and functions.
🌐
Readthedocs
sphinxcontrib-napoleon.readthedocs.io β€Ί en β€Ί latest β€Ί example_google.html
Example Google Style Python Docstrings β€” napoleon 0.7 documentation
# -*- coding: utf-8 -*- """Example Google style docstrings. This module demonstrates documentation as specified by the `Google Python Style Guide`_. Docstrings may extend over multiple lines. Sections are created with a section header and a colon followed by a block of indented text.
🌐
Medium
medium.com β€Ί @syedar.sohail β€Ί docstring-and-why-is-it-important-python-classes-modules-and-functions-95fee5247ff5
Docstring and why is it important ? β€” Python Classes, Modules and Functions | by Sohail | Medium
October 30, 2022 - Please do not confuse thinking comments and Docstrings are the same. well, they may highly look similar in the way they work but there is a lot of difference. Comments are written generally to show some unusual portions of code and for fixing the bugs. While Docstrings are the right tool for documenting the classes, functions, modules and packages.
🌐
EDUCBA
educba.com β€Ί home β€Ί software development β€Ί software development tutorials β€Ί python tutorial β€Ί python docstring
Python Docstring | Complete Guide to Python Docstring
March 24, 2023 - Python Doctstring is the documentation string that occurs at class, method, module or function level. A docstring is simply a multi-line string that is not assigned to anything. It is specified in the source code that is used to document a specific ...
Address: Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
SourceForge
epydoc.sourceforge.net β€Ί manual-docstring.html
Python Docstrings - Epydoc
Python documentation strings (or docstrings) provide a convenient way of associating documentation with Python modules, functions, classes, and methods. An object's docsting is defined by including a string constant as the first statement in the object's definition.
🌐
Medium
medium.com β€Ί @farihatulmaria β€Ί what-are-docstrings-in-python-how-do-you-write-and-access-them-16f54d982ca3
What are docstrings in Python? How do you write and access them? | by Farihatul Maria | Medium
August 3, 2024 - Docstrings in Python are string literals that appear right after the definition of a module, function, class, or method. They are used to document what the code does, describe its purpose, and provide information on how to use it.