🌐
Readthedocs
numpydoc.readthedocs.io › en › latest › format.html
Style guide — numpydoc v1.11.0rc1.dev0 Manual
This document describes the syntax and best practices for docstrings used with the numpydoc extension for Sphinx. ... For an accompanying example, see example.py. Some features described in this document require a recent version of numpydoc. For example, the Yields section was added in numpydoc 0.6. We mostly follow the standard Python style ...
🌐
Sphinx
sphinx-doc.org › en › master › usage › extensions › example_numpy.html
Example NumPy Style Python Docstrings — Sphinx documentation
"""Example NumPy style docstrings. This module demonstrates documentation as specified by the `NumPy Documentation HOWTO`_. Docstrings may extend over multiple lines. Sections are created with a section header followed by an underline of equal length. Example ------- Examples can be given using either the ``Example`` or ``Examples`` sections.
Discussions

coding style - What are the most common Python docstring formats? - Stack Overflow
I prefer Google format, which is ... space as Numpydoc does. 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 ... More on stackoverflow.com
🌐 stackoverflow.com
PyCharm not rendering DocStrings correctly
Make you you set the write docstring format in settings. In the “Python integrated tools” section. If you search “Google” in settings it’s one of the hits More on reddit.com
🌐 r/pycharm
6
5
April 30, 2023
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
Getting Doxygen to work well with Python docstrings
Ok, it has to be asked - why bother when the Python community has sphinx ? One of the greatest complaints we hear in the scientific community when trying to convince our peers to try Python in lieu of Matlab is the lack of centralized, comprehensive documentation for the various libraries they need. That's slowly changing with readthedocs and other projects, but how is introducing another documentation system going to improve the ecosystem? What does Doxygen offer that the existing Python documentation system doesn't? More on reddit.com
🌐 r/programming
7
19
January 16, 2016
🌐
Medium
mr-amit.medium.com › numpy-docstring-explained-3d2e3b3f017a
NumPy Docstring Explained. If you think you need to spend $2,000… | by It's Amit | Medium
March 6, 2025 - Every docstring starts with a clear, one-line summary. Think of this as the elevator pitch for your function — what it does, in the simplest terms. Follow it up with a bit more detail if necessary, but keep it concise. ... Notice how the summary gets straight to the point? No fluff, no unnecessary details — just the essence of what the function does. ... Next, describe the inputs your function expects. NumPy-style docstrings use the Parameters section, formatted like this:
🌐
Readthedocs
sphinxcontrib-napoleon.readthedocs.io › en › latest › example_numpy.html
Example NumPy Style Python Docstrings — napoleon 0.7 documentation
# -*- coding: utf-8 -*- """Example NumPy style docstrings. This module demonstrates documentation as specified by the `NumPy Documentation HOWTO`_. Docstrings may extend over multiple lines. Sections are created with a section header followed by an underline of equal length.
🌐
GitHub
github.com › douglasdavis › numpydoc.el
GitHub - douglasdavis/numpydoc.el: Insert NumPy style docstrings in Python functions. · GitHub
docstr: Docstring insertion support for any programming language, including NumPy style Python (it has a programmable interface but requires a bit more setup to get the utility provided numpydoc.el).
Starred by 51 users
Forked by 8 users
Languages: Emacs Lisp
🌐
Pyansys
dev.docs.pyansys.com › doc-style › docstrings.html
Numpydoc docstrings — PyAnsys developer's guide
extensions = [ ..., "sphinx.ext.autodoc.typehints", "sphinx.ext.napoleon", "numpydoc", ..., ] autodoc_typehints = "description" When using type hints in this way, you can omit the type information in the “Parameters” and “Returns” sections. Because Python docstrings are written using reStructuredText syntax, you can take advantage of some of the directives available in this plaintext markup language.
🌐
Lsst
developer.lsst.io › python › numpydoc.html
Documenting Python APIs with docstrings — LSST DM Developer Guide main documentation
We organize Python docstrings into sections that appear in a common order. This format is based on the original Numpydoc Style Guide (used by NumPy, SciPy, and Astropy, among other scientific Python packages), though this style guide includes several DM-specific clarifications.
🌐
NumPy
numpy.org › doc › 1.20 › docs › howto_document.html
A Guide to NumPy Documentation — NumPy v1.20 Manual
January 31, 2021 - We welcome being alerted to cases we should add to the NumPy style rules. When using Sphinx in combination with the numpy conventions, you should use the numpydoc extension so that your docstrings will be handled correctly. For example, Sphinx will extract the Parameters section from your docstring ...
🌐
GitHub
github.com › emacsmirror › numpydoc
GitHub - emacsmirror/numpydoc: NumPy style docstring insertion · GitHub
An Emacs Lisp package to automatically insert NumPy style docstrings for Python functions.
Author: emacsmirror
Find elsewhere
🌐
Plain English
python.plainenglish.io › how-to-write-numpy-style-docstrings-a092121403ba
How to Write NumPy-Style Docstrings | Python in Plain English
May 25, 2022 - As so often in the Python world, there are a few best practices on how to do something, in this case how to write docstrings properly. Three main styles have evolved: the traditional style, the Google style, and the NumPy style. I advocate the NumPy style because it is very human-readable (in contrast to the traditional style) and it is widely used in the scientific and technical community, which is my own domain.
🌐
NumPy
numpy.org › doc › 1.19 › docs › howto_document.html
A Guide to NumPy/SciPy Documentation — NumPy v1.19 Manual
Our docstring standard uses re-structured text (reST) syntax and is rendered using Sphinx (a pre-processor that understands the particular documentation style we are using).
🌐
Better Programming
betterprogramming.pub › 3-different-docstring-formats-for-python-d27be81e0d68
3 Different Docstring Formats for Python | by Yash Salvi | Better Programming
April 27, 2022 - NumPy style tends to require more vertical space, whereas Google-style tends to use more horizontal space. Google-style tends to be easier to read for short and simple docstrings, whereas NumPy-style tends to be easier to read for long and in-depth docstrings.
🌐
pythontutorials
pythontutorials.net › blog › numpy-style-docstrings
Mastering NumPy Style Docstrings: A Comprehensive Guide — pythontutorials.net
NumPy style docstrings are a specific convention for writing docstrings that have become widely adopted in the scientific Python community. They offer a structured and detailed format for documenting code, which is especially useful for complex ...
🌐
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 - NumPy style docstrings are commonly used in scientific computing and data analysis projects. They offer a concise and structured approach to documenting code. With sections like parameters, return values, and raised exceptions, this format ensures that crucial information is clearly communicated ...
Author: alimanfoo
🌐
pyOpenSci
pyopensci.org › python-package-guide › documentation › write-user-documentation › document-your-code-api-docstrings.html
Document the code in your package’s API using docstrings
In the example above, you saw the use of numpy-style docstrings to describe data types that are passed into functions as parameters or into classes as attributes. In a numpy-style docstring you add those types in the Parameters section of the docstring.
🌐
NumPy
numpy.org › doc › 1.21 › docs › howto_document.html
A Guide to NumPy Documentation — NumPy v1.21 Manual
June 22, 2021 - We welcome being alerted to cases we should add to the NumPy style rules. When using Sphinx in combination with the numpy conventions, you should use the numpydoc extension so that your docstrings will be handled correctly. For example, Sphinx will extract the Parameters section from your docstring and convert it into a field list.
🌐
Sphinx
sphinx-doc.org › en › master › usage › extensions › napoleon.html
sphinx.ext.napoleon – Support for NumPy and Google style docstrings — Sphinx documentation
Napoleon is a pre-processor that parses NumPy and Google style docstrings and converts them to reStructuredText before Sphinx attempts to parse them.
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