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-0008
PEP 8 – Style Guide for Python Code | peps.python.org
This document gives coding conventions for the Python code comprising the standard library in the main Python distribution. Please see the companion informational PEP describing style guidelines for the C code in the C implementation of Python.
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
Be sure to use the right style for module, function, method docstrings and inline comments. Python uses docstrings to document code. A docstring is a string that is the first statement in a package, module, class or function. These strings can be extracted automatically through the __doc__ ...
🌐
Real Python
realpython.com β€Ί documenting-python-code
Documenting Python Code: A Complete Guide – Real Python
July 17, 2026 - >>> help(say_hello) Help on function say_hello in module __main__: say_hello(name) A simple function that says hello... Richie style Β· Python has one more feature that simplifies docstring creation. Instead of directly manipulating the __doc__ property, the strategic placement of the string literal directly below the object will automatically set the __doc__ value.
🌐
Josh Di Mella
joshdimella.com β€Ί blog β€Ί python-docstring-formats-best-practices
A Guide to Python Docstring Formats: Choosing the Right Style for Your Code | Josh Di Mella | Software Engineer
May 31, 2023 - Google style docstrings follow a structured format and are widely adopted in the Python community. They consist of a summary line, detailed explanations, and specific sections for parameters, return values, and raised exceptions. This format ensures comprehensive and standardized documentation, ...
🌐
Sphinx
sphinx-doc.org β€Ί en β€Ί master β€Ί usage β€Ί extensions β€Ί example_google.html
Example Google Style Python Docstrings β€” Sphinx documentation
Choose one convention to document module level variables and be consistent with it. Todo: * For module TODOs * You have to also use ``sphinx.ext.todo`` extension .. _Google Python Style Guide: https://google.github.io/styleguide/pyguide.html """ module_level_variable1 = 12345 module_level_variable2 = 98765 """int: Module level variable documented inline.
Find elsewhere
🌐
Lsst
developer.lsst.io β€Ί v β€Ί DM-5063 β€Ί docs β€Ί py_docs.html
Documenting Python Code β€” LSST DM Developer Guide latest documentation
The one line summary can be used alone only in extremely trivial cases, such as Python properties. Keep in mind our style guideline for placing the short summary on the same line as the opening (and closing, if used alone) docstring delimiters.
🌐
Python Developer's Guide
devguide.python.org β€Ί documentation β€Ί start-documenting
Getting started
February 20, 2026 - The Python language has a substantial body of documentation, much of it contributed by various authors. The markup used for the Python documentation is reStructuredText, developed by the docutils p...
🌐
Cornell Computer Science
cs.cornell.edu β€Ί courses β€Ί cs1110 β€Ί 2019fa β€Ί resources β€Ί style
Python Programming Style
August 24, 2019 - Unlike Java, Python does not have ... but adheres to Python guidelines for docstring comments. In particular, our style contains much more useful information than most Python documentation that you will see online....
🌐
Lsst
developer.lsst.io β€Ί v β€Ί DM-9256 β€Ί docs β€Ί py_docs.html
Documenting Python APIs β€” LSST DM Developer Guide latest documentation
This deviation from our reST Style Guide is in keeping with NumPy community idioms, and required by our Sphinx tooling. We organize Python docstrings into sections that appear in a common order. This format follows the Numpydoc format (used by NumPy, SciPy, and Astropy, among other scientific Python packages) rather than the format described in PEP 287.
🌐
Mit
drake.mit.edu β€Ί styleguide β€Ί pyguide.html
Google Python Style Guide for Drake
The docstring for a @property data descriptor should use the same style as the docstring for an attribute or a function argument ("""The Bigtable path.""", rather than """Returns the Bigtable path."""). Certain aspects of a function should be documented in special sections, listed below.
🌐
DataCamp
datacamp.com β€Ί tutorial β€Ί docstrings-python
Python Docstrings Tutorial : Examples & Format for Pydoc, Numpy, Sphinx Doc Strings | DataCamp
February 14, 2025 - You'll be looking over the example ... then you can easily follow along with other formats as well. Sphinx is the easy and traditional style, verbose, and was initially created specifically for Python Documentation....
🌐
GeeksforGeeks
geeksforgeeks.org β€Ί python β€Ί python-docstrings
Python Docstrings - GeeksforGeeks
September 19, 2025 - Google style docstrings follow a specific format and are inspired by Google's documentation style guide. They provide a structured way to document Python code, including parameters, return values and descriptions.
🌐
Python
docs.python.org β€Ί 3 β€Ί builtins β€Ί stdtypes.html
Built-in Types β€” Python 3.14.7 documentation
The functools.cmp_to_key() utility is available to convert a 2.x style cmp function to a key function.
🌐
JetBrains
jetbrains.com β€Ί help β€Ί pycharm β€Ί using-docstrings-to-specify-types.html
Specify types with docstrings | PyCharm Documentation
September 1, 2025 - By the way, you can use quick documentation for the function. If you place the caret at the function name and press Ctrl+Q, you will see: Note that for reStructuredText it's possible to specify types in two formats: :param param_type param_name: parameter description (type description is on the same line as the parameter description). :type param_name: param_type (type description is on a separate line) ... Press Ctrl+Alt+S and go to Build, Execution, Deployment | Python Debugger.
🌐
Pandas
pandas.pydata.org β€Ί docs β€Ί development β€Ί contributing_docstring.html
pandas docstring guide β€” pandas 3.0.5 documentation
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). reStructuredText is a markup language that allows encoding ...
🌐
Python Developer's Guide
devguide.python.org β€Ί documentation β€Ί markup
reStructuredText markup
July 28, 2026 - All reST files use an indentation of 3 spaces; no tabs are allowed. The maximum line length is 80 characters for normal text, but tables, deeply indented code samples and long links may extend beyond that.
🌐
W3Schools
w3schools.com β€Ί python β€Ί ref_string_format.asp
Python String format() Method
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.