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

Answer from daouzli on Stack Overflow
🌐
Python
peps.python.org β€Ί pep-0287
PEP 287 – reStructuredText Docstring Format | peps.python.org
March 25, 2002 - When plaintext hasn’t been expressive enough for inline documentation, Python programmers have sought out a format for docstrings. This PEP proposes that the reStructuredText markup be adopted as a standard markup format for structured plaintext documentation in Python docstrings, and for PEPs and ancillary documents as well.
🌐
Readthedocs
sphinx-rtd-tutorial.readthedocs.io β€Ί en β€Ί latest β€Ί docstrings.html
Writing docstrings β€” Sphinx-RTD-Tutorial documentation
If you are using VS code, the Python Docstring extension can be used to auto-generate a docstring snippet once a function/class has been written.
Discussions

coding style - What are the most common Python docstring formats? - Stack Overflow
Epytext format is IMHO the same higgledy-piggledy mess as reST format. 2018-11-06T10:13:16.24Z+00:00 ... Save this answer. ... Show activity on this post. The Google style guide contains an excellent Python style guide. It includes conventions for readable docstring syntax that offers better ... More on stackoverflow.com
🌐 stackoverflow.com
Is there a Sphinx reST Python docstring field for yields? - Stack Overflow
I'm trying to use reST-style docstrings, i.e. def foo(bar): """a method that takes a bar :param bar: a Bar instance :type bar: Bar Is there a standard way to document y... More on stackoverflow.com
🌐 stackoverflow.com
python - Utilizing Sphinx with reStructuredText formatted docstrings - Stack Overflow
If we want to dig further back to the definition of the reST docstring syntax the archives of the Doc-SIG - Python Documentation Special Interest Group would be the way to go, but a good enough overview is given by PEP 256 - Rationale dated 01-Jun-2001. More on stackoverflow.com
🌐 stackoverflow.com
What format do you use for your docstrings?
ReST since that is what is supported natively by Sphinx. Tried Google style docstrings and could never get it to work easily with RTD More on reddit.com
🌐 r/Python
12
11
July 21, 2017
🌐
Stack Abuse
stackabuse.com β€Ί common-docstring-formats-in-python
Common Docstring Formats in Python
August 26, 2023 - They're essentially comments that ... docstrings, and they each have their own strengths and weaknesses. The most commonly used formats are reStructuredText (reST), Google, NumPy/SciPy, and Epytext....
🌐
GitHub
gist.github.com β€Ί jesugmz β€Ί d83b5e9de7ccc16f71c02adf7d2f3f44
Python docstring reStructuredText style Β· GitHub
Python docstring reStructuredText style Β· Raw Β· Python-docstring-restructuredtext-style.rst Β· Signatures of functions, methods and class constructors can be given like they would be written in Python. Default values for optional arguments can be given (but if they contain commas, they will confuse the signature parser).
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
🌐
GitHub
gist.github.com β€Ί nipunsadvilkar β€Ί fec9d2a40f9c83ea7fd97be59261c400
What is the standard Python docstring format? Β· GitHub
There follows the main used formats for docstrings. Historically a javadoc like style was prevalent, so it was taken as a base for Epydoc (with the called Epytext format) to generate documentation. ... """ 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 """ Nowadays, the probably more prevalent format is the reStructuredText (reST) format that is used by Sphinx to generate documentation.
🌐
Real Python
realpython.com β€Ί how-to-write-docstrings-in-python
How to Write Docstrings in Python – Real Python
August 25, 2025 - ... Common docstring formats include reStructuredText (reST), Google-style, NumPy-style, and doctest-style, each with its own conventions for organizing information about parameters, returns, and examples.
Find elsewhere
🌐
Pandas
pandas.pydata.org β€Ί docs β€Ί development β€Ί contributing_docstring.html
pandas docstring guide β€” pandas 3.0.5 documentation
The first conventions every Python docstring should follow are defined in PEP-257. As PEP-257 is quite broad, other more specific standards also exist. In the case of pandas, the NumPy docstring convention is followed. These conventions are explained in this document: ... The standard uses reStructuredText (reST).
🌐
Medium
medium.com β€Ί @24littledino β€Ί docstring-in-python-f49635e99f36
Docstring in Python. Introduction and Example of reST… | by Little Dino | Medium
February 27, 2022 - The code could be a module, function, class, or method definition, or anything you want to elaborate. There are a lot of ways you can describe the purpose or the idea of your code, but reStructuredText (reST) is a popular format in Python.
🌐
Sweetpea-org
sweetpea-org.github.io β€Ί guide β€Ί contributing β€Ί rest_style_guide.html
reStructuredText Style Guide β€” SweetPea documentation
(We only use python and rest so far.) The code-block directive is smart and can handle multiple line breaks. ... Creates a glossary of terms where each term has a definition and can be linked to with the :term: role. ... Creates a table of contents tree. The toctree directive is used on any page that collects other pages of documentation, such as docs/_source/index.rst. There is generally not need for use of directives within the Python docstrings, but we do make regular use of admonitions.
Top answer
1 of 2
2

The two formats are actually the same. This can be confusing but what's called the Info field lists can be considered the reST docstring syntax. If you look carefully at the version number it's been around since Sphinx version 0.4, next if we look at the current Sphinx change list it remits to a change list that predates version 1.0... The earliest mention there is:

Release 0.4 (Jun 23, 2008)

==========================

  • Sphinx now interprets field lists with fields like :param foo: in description units.

If we want to dig further back to the definition of the reST docstring syntax the archives of the Doc-SIG - Python Documentation Special Interest Group would be the way to go, but a good enough overview is given by PEP 256 - Rationale dated 01-Jun-2001. The document that emerged from then and is most frequently cited only makes a loose recommendation:

PEP 257 -- Docstring Conventions

Python is case sensitive and the argument names can be used for keyword arguments, so the docstring should document the correct argument names. It is best to list each argument on a separate line.

To summarize things, the reST docstring syntax consists simply of using reST Field Lists! (the NumPy and Google styles are just different styles of also writing reST Field Lists)!

Field List - reStructuredText Markup Specification

Field lists are mappings from field names to field bodies,

(...)

The interpretation of individual words in a multi-word field name is up to the application. The application may specify a syntax for the field name.

Syntax diagram (simplified):

+--------------------+----------------------+
| ":" field name ":" | field body           |
+-------+------------+                      |
        | (body elements)+                  |
        +-----------------------------------+

It's up to the application to specify the syntax of the field names; so what Sphinx documentation generator specifies for the 2 example syntaxes in the question is that they are equivalent (this does not necessarily hold if you change to a different documentation generator).

2 of 2
1

Thanks to @mzjin's answer in the comments: this link describes that it is possible since v0.4.

The below example is given in the link, which is exactly what I was looking for.

py:function:: send_message(sender, recipient, message_body, [priority=1])
   """
   Send a message to a recipient

   :param str sender: The person sending the message
   :param str recipient: The recipient of the message
   :param str message_body: The body of the message
   :param priority: The priority of the message, can be a number 1-5
   :type priority: integer or None
   :return: the message id
   :rtype: int
   :raises ValueError: if the message_body exceeds 160 characters
   :raises TypeError: if the message_body is not a basestring
   """
🌐
Pandas
pandas.pydata.org β€Ί pandas-docs β€Ί stable β€Ί development β€Ί contributing_docstring.html
pandas docstring guide β€” pandas 3.0.3 documentation
The first conventions every Python docstring should follow are defined in PEP-257. As PEP-257 is quite broad, other more specific standards also exist. In the case of pandas, the NumPy docstring convention is followed. These conventions are explained in this document: ... The standard uses reStructuredText (reST).
🌐
Programiz
programiz.com β€Ί python-programming β€Ί docstrings
Python Docstrings (With Examples)
The docstrings for a Python package is written in the package's __init__.py file. It should contain all the available modules and sub-packages exported by the package. We can write docstring in many formats like the reStructured text (reST) format, Google format or the NumPy documentation format.
🌐
Stack Abuse
stackabuse.com β€Ί python-docstrings
Python Docstrings
August 23, 2023 - You might expect that there is just one binding docstring format. Unfortunately, there is more than one, and all of these format variants work with multi-line docstrings. reStructured text (reST) / Sphinx: This is the Official Python documentation standard.
🌐
Python-sprints
python-sprints.github.io β€Ί pandas β€Ί guide β€Ί pandas_docstring.html
pandas docstring guide β€” Python documentation
In the case of pandas, the numpy ... documentation) numpydoc is a Sphinx extension to support the numpy docstring convention. The standard uses reStructuredText (reST)....
🌐
DeepDocs
deepdocs.dev β€Ί home β€Ί 8 practical python docstring examples & patterns
8 Practical Python Docstring Examples & Patterns | DeepDocs
November 25, 2025 - RESTful API docstrings, structured according to the OpenAPI Specification (formerly Swagger), are designed for this purpose. They describe HTTP endpoints, request/response models, and status codes. This format is a prime example of how python ...
🌐
Linux find Examples
queirozf.com β€Ί entries β€Ί python-docstrings-reference-examples
Python Docstrings: Reference & Examples
September 1, 2020 - Examples to help you document your Python code using any of the commonly used docstring styles.