🌐
Python
peps.python.org › pep-0257
PEP 257 – Docstring Conventions | peps.python.org
PEP 257 – Docstring Conventions · Author: David Goodger <goodger at python.org>, Guido van Rossum <guido at python.org> Discussions-To: Doc-SIG list · Status: Active · Type: Informational · Created: 29-May-2001 · Post-History: 13-Jun-2001 · Table of Contents ·
🌐
Mkdocstrings
mkdocstrings.github.io › python › usage › configuration › docstrings
Docstrings - mkdocstrings-python
There are sections for documenting ... data and can therefore be rendered in different ways. Possible values: "table": a simple table, usually with type, name and description columns...
🌐
Pandas
pandas.pydata.org › docs › development › contributing_docstring.html
pandas docstring guide — pandas 3.0.2 documentation
Docstrings must be defined with three double-quotes. No blank lines should be left before or after the docstring. The text starts in the next line after the opening quotes.
🌐
Python-sprints
python-sprints.github.io › pandas › guide › pandas_docstring.html
pandas docstring guide — Python documentation
Docstrings must be defined with three double-quotes. No blank lines should be left before or after the docstring. The text starts in the next line after the opening quotes.
🌐
Readthedocs
numpydoc.readthedocs.io › en › latest › format.html
Style guide — numpydoc v1.11.0rc0.dev0 Manual
References are meant to augment the docstring, but should not be required to understand it. References are numbered, starting from one, in the order in which they are cited. ... Where references like [1] appear in a tables within a numpydoc docstring, the table markup will be broken by numpydoc processing.
🌐
Real Python
realpython.com › documenting-python-code
Documenting Python Code: A Complete Guide – Real Python
December 21, 2023 - Docstring Formats: The different docstring “formats” (Google, NumPy/SciPy, reStructuredText, and Epytext) Documenting your Python code is all centered on docstrings. These are built-in strings that, when configured correctly, can help your users and yourself with your project’s documentation.
🌐
DataCamp
datacamp.com › tutorial › docstrings-python
Python Docstrings Tutorial : Examples & Format for Pydoc, Numpy, Sphinx Doc Strings | DataCamp
February 14, 2025 - !python -m pydoc -b · ^C · The moment you run the above cell, a new window will open on an arbitrary port number, and the web browser will look similar to the one shown below. Let's look at the documentation of the h5py module, which is a file format used to store weights of neural network architecture. In the table below, you can see a comparison of the different types of docstring formats we've mentioned above: Sphinx Style: Often used in large projects where comprehensive documentation is required.
🌐
Programiz
programiz.com › python-programming › docstrings
Python Docstrings (With Examples)
In this tutorial, we will learn about Python docstrings. More specifically, we will learn how and why docstrings are used with the help of examples.
Find elsewhere
🌐
Python
peps.python.org › pep-0287
PEP 287 – reStructuredText Docstring Format | peps.python.org
March 25, 2002 - The processed form (HTML etc.) ... links!); tables; images for diagrams etc.; pleasant, readable styled text. The reStructuredText parser is available now, part of the Docutils project. Standalone reStructuredText documents and PEPs can be converted to HTML; other output format writers are being worked on and will become available over time. Work is progressing on a Python source “Reader” which will implement auto-documentation from docstrings...
🌐
Readthedocs
sphinxcontrib-napoleon.readthedocs.io › en › latest › example_google.html
Example Google Style Python Docstrings — napoleon 0.7 documentation
If attribute, parameter, and return types are annotated according to `PEP 484`_, they do not need to be included in the docstring: Args: param1 (int): The first parameter. param2 (str): The second parameter. Returns: bool: The return value. True for success, False otherwise. .. _PEP 484: https://www.python.org/dev/peps/pep-0484/ """ def function_with_pep484_type_annotations(param1: int, param2: str) -> bool: """Example function with PEP 484 type annotations.
🌐
Readthedocs
sphinx-rtd-theme.readthedocs.io › en › stable › demo › lists_tables.html
4. Lists & Tables — Read the Docs Sphinx Theme 3.1.0 documentation
8 9 This text tests for the formatting of docstrings generated from output 10 ``sphinx.ext.autodoc``. Which contain reST, but sphinx nests it in the ... This is a note nested in a list. ... I kept saying that, “deeper down the rabbit hole”. yahoo · I cackle at night yahoo. ... A man of python destiny, hopes and dreams.
🌐
Medium
medium.com › internet-of-technology › how-to-properly-display-tables-in-python-docstrings-in-vs-code-8e334c225f01
Docstring Table Rendering Issues in VS Code | Internet of Technology
August 13, 2024 - This article compares reStructuredText (reST) and Markdown tables in VS code and investigates docstring table rendering issues with reST. Photo by Clément Hélardot on Unsplash. reST is the default markup language for Sphinx, a tool for generating Python documentation.
🌐
Real Python
realpython.com › how-to-write-docstrings-in-python
How to Write Docstrings in Python – Real Python
June 19, 2025 - This is because the .__doc__ attribute returns only the top-level docstring of the object, often just a summary. In contrast, help() pulls in structured metadata and provides a more comprehensive breakdown, especially for complex objects like modules and classes. Python includes a powerful built-in documentation tool called pydoc that can display and generate documentation from your docstrings.
Top answer
1 of 6
1389

Formats

Python docstrings can be written following several formats as the other posts showed. However the default Sphinx docstring format was not mentioned and is based on reStructuredText (reST). You can get some information about the main formats in this blog post.

Note that the reST is recommended by the PEP 287

There follows the main used formats for docstrings.

- Epytext

Historically a javadoc like style was prevalent, so it was taken as a base for Epydoc (with the called Epytext format) to generate documentation.

Example:

"""
This is a javadoc style.

@param param1: this is a first param
@param param2: this is a second param
@return: this is a description of what is returned
@raise keyError: raises an exception
"""

- reST

Nowadays, the probably more prevalent format is the reStructuredText (reST) format that is used by Sphinx to generate documentation. Note: it is used by default in JetBrains PyCharm (type triple quotes after defining a method and hit enter). It is also used by default as output format in Pyment.

Example:

"""
This is a reST style.

:param param1: this is a first param
:param param2: this is a second param
:returns: this is a description of what is returned
:raises keyError: raises an exception
"""

- Google

Google has their own format that is often used. It also can be interpreted by Sphinx (ie. using Napoleon plugin).

Example:

"""
This is an example of Google style.

Args:
    param1: This is the first param.
    param2: This is a second param.

Returns:
    This is a description of what is returned.

Raises:
    KeyError: Raises an exception.
"""

Even more examples

- Numpydoc

Note that Numpy recommend to follow their own numpydoc based on Google format and usable by Sphinx.

"""
My numpydoc description of a kind
of very exhautive numpydoc format docstring.

Parameters
----------
first : array_like
    the 1st param name `first`
second :
    the 2nd param
third : {'value', 'other'}, optional
    the 3rd param, by default 'value'

Returns
-------
string
    a value in a string

Raises
------
KeyError
    when a key error
OtherError
    when an other error
"""

Converting/Generating

It is possible to use a tool like Pyment to automatically generate docstrings to a Python project not yet documented, or to convert existing docstrings (can be mixing several formats) from a format to an other one.

Note: The examples are taken from the Pyment documentation

2 of 6
354

The Google style guide contains an excellent Python style guide. It includes conventions for readable docstring syntax that offers better guidance than PEP-257. For example:

def square_root(n):
    """Calculate the square root of a number.

    Args:
        n: the number to get the square root of.
    Returns:
        the square root of n.
    Raises:
        TypeError: if n is not a number.
        ValueError: if n is negative.

    """
    pass

I like to extend this to also include type information in the arguments, as described in this Sphinx documentation tutorial. For example:

def add_value(self, value):
    """Add a new value.

       Args:
           value (str): the value to add.
    """
    pass
🌐
Google
google.github.io › styleguide › pyguide.html
Google Python Style Guide
The presence of a trailing comma ... to our Python code auto-formatter Black or Pyink to direct it to auto-format the container of items to one item per line when the , after the final element is present. Yes: golomb3 = [0, 1, 3] golomb4 = [ 0, 1, 4, 6, ] ... Two blank lines between top-level definitions, be they function or class definitions. One blank line between method definitions and between the docstring of a class ...
🌐
Dataquest
dataquest.io › blog › documenting-in-python-with-docstrings
Tutorial: Documenting in Python with Docstrings
December 13, 2024 - The Python docstring of this function is enclosed between three double quotes from both sides. As you can see, this string explains what this function does and indicates how we can change its functionality — and what happens if it doesn't support the action we want it to perform.
🌐
Doruk Kilitcioglu
dorukkilitcioglu.com › 2018 › 08 › 18 › python-better-docstring.html
A case for better Python docstrings - Doruk Kilitcioglu
August 18, 2018 - Although Python is dynamically ... in the docstring, so that whoever is looking at your code doesn’t have to guesstimate what exactly is being passed into the function. The default argument can sometimes indicate the type, but when the default is None, it’s going to be tough. The Google style guide for Python defines a syntax that makes way more sense. Below is an example directly taken from their style guide: def fetch_bigtable_rows(big_table, keys, ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-docstrings
Python Docstrings - GeeksforGeeks
September 19, 2025 - Each method docstring documents parameters and return values. Proper indentation ensures readability and compatibility with tools like help(). Comments (#): Explain code but are ignored by Python at runtime.