🌐
Readthedocs
sphinxcontrib-napoleon.readthedocs.io β€Ί en β€Ί latest β€Ί example_numpy.html
Example NumPy Style Python Docstrings β€” napoleon 0.7 documentation
Attributes ---------- module_level_variable1 : int Module level variables may be documented in either the ``Attributes`` section of the module docstring, or in an inline docstring immediately following the variable. Either form is acceptable, but the two should not be mixed. Choose one convention to document module level variables and be consistent with it. .. _NumPy Documentation HOWTO: https://github.com/numpy/numpy/blob/master/doc/HOWTO_DOCUMENT.rst.txt """ module_level_variable1 = 12345 module_level_variable2 = 98765 """int: Module level variable documented inline.
🌐
Readthedocs
numpydoc.readthedocs.io β€Ί en β€Ί latest β€Ί format.html
Style guide β€” numpydoc v1.11.1.dev1+gca74aae44 Manual
If a method has an equivalent function (which is the case for many ndarray methods for example), the function docstring should contain the detailed documentation, and the method docstring should refer to it. Only put brief summary and See Also sections in the method docstring. The method should use a Returns or Yields section, as appropriate. Instances of classes that are part of the NumPy API (for example np.r_ np.c_, np.index_exp, etc.) may require some care.
Discussions

What is meant (in this article) by saying Google Docstrings don't have a "Formal Specification" while Numpydoc Docstrings do?
https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings More on reddit.com
🌐 r/learnpython
5
3
January 27, 2022
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
No More Docstring Despair: Highlight Them in VSCode!
This is actually a great idea. Well done. Ideally, this should be built-in in VScode. More on reddit.com
🌐 r/Python
30
103
March 12, 2024
How to automatically make line breaks in the long python docstring?
https://marketplace.visualstudio.com/items?itemName=stkb.rewrap More on reddit.com
🌐 r/vscode
4
0
April 21, 2023
🌐
NumPy
numpy.org β€Ί doc β€Ί 1.19 β€Ί docs β€Ί howto_document.html
A Guide to NumPy/SciPy Documentation β€” NumPy v1.19 Manual
For example, the Yields section ... world, so we avoid it in the documentation to avoid confusion. A documentation string (docstring) is a string that describes a module, function, class, or method definition....
🌐
NumPy
numpy.org β€Ί doc β€Ί 1.20 β€Ί docs β€Ί howto_document.html
A Guide to NumPy Documentation β€” NumPy v1.20 Manual
January 31, 2021 - Using numpydoc will also avoid the reStructuredText errors produced by plain Sphinx when it encounters numpy docstring conventions like section headers (e.g.
🌐
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 - The output for both docstrings looks similar, the main difference between the two styles is that Google uses indentation to separate sections, whereas NumPy uses underlines. NumPy style tends to require more vertical space, whereas Google-style ...
🌐
NumPy
numpy.org β€Ί doc β€Ί 1.21 β€Ί docs β€Ί howto_document.html
A Guide to NumPy Documentation β€” NumPy v1.21 Manual
June 22, 2021 - Using numpydoc will also avoid the reStructuredText errors produced by plain Sphinx when it encounters numpy docstring conventions like section headers (e.g.
🌐
Sphinx
sphinx-doc.org β€Ί en β€Ί master β€Ί usage β€Ί extensions β€Ί example_numpy.html
Example NumPy Style Python Docstrings β€” Sphinx documentation
Attributes ---------- module_level_variable1 : int Module level variables may be documented in either the ``Attributes`` section of the module docstring, or in an inline docstring immediately following the variable. Either form is acceptable, but the two should not be mixed. Choose one convention to document module level variables and be consistent with it. .. _NumPy docstring standard: https://numpydoc.readthedocs.io/en/latest/format.html#docstring-standard """ module_level_variable1 = 12345 module_level_variable2 = 98765 """int: Module level variable documented inline.
🌐
DataCamp
datacamp.com β€Ί tutorial β€Ί docstrings-python
Python Docstrings Tutorial : Examples & Format for Pydoc, Numpy, Sphinx Doc Strings | DataCamp
February 14, 2025 - Google Style: Ideal for projects where simplicity and readability are prioritized, especially within organizations using Google's style guides. NumPy Style: Best suited for projects requiring detailed and extensive documentation, common in data science and scientific computing.
Find elsewhere
🌐
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 - A docstring is a multi-line string in Python that acts as a guide to explain what a module, function, class, or method does. Think of it as a small note left behind to make your (and everyone else’s) life easier when reading or using the code. Now, NumPy takes this concept and levels it up by creating highly structured, detailed docstrings that ensure its vast library of functions is easy to understand β€” even for beginners.
🌐
Lsst
developer.lsst.io β€Ί python β€Ί numpydoc.html
Documenting Python APIs with docstrings β€” LSST DM Developer Guide main documentation
These sections β€” including names, capitalizations, and relative order β€” are highly prescribed by the Numpydoc standard and the tooling that works in that ecosystem including documentation builders (Sphinx) and linters (pydocstyle). You cannot add custom sections. Also note that the sections are title cased (e.g. β€œSee Also”), as opposed to the sentence casing recommended otherwise in our User documentation style guide. For summaries of how these docstring sections are composed in specific contexts, see:
🌐
Reddit
reddit.com β€Ί r/learnpython β€Ί what is meant (in this article) by saying google docstrings don't have a "formal specification" while numpydoc docstrings do?
r/learnpython on Reddit: What is meant (in this article) by saying Google Docstrings don't have a "Formal Specification" while Numpydoc Docstrings do?
January 27, 2022 -

Hi all,

Currently embarking on my first "professional" python module build for work. Plenty of scripts and the odd python module for personal use or minor things, but this is "the big one".

We were talking about which docstring format to use. I like the Numpydoc format, mostly because I use a lot of Numpy/Scipy/Astropy and thats the format I see a lot, while my colleague prefers Google format. Nothing major, and I am tempted to go Google format just to align with another team's project.

But I found this article which gives a table of several docstring formats. Both Google and Numpy are accepted by Sphynx (which is great), but it says that Numpy has a Formal Specification while Google does not. Yet I cant find any mention in the rest of the article about what that actually means.

I would assume its something like Numpydoc being more rigid in what you call things, but Google seems pretty rigid to me. What am I missing? (And does anyone here have a preference between the two?)

🌐
Python-sprints
python-sprints.github.io β€Ί pandas β€Ί guide β€Ί pandas_docstring.html
pandas docstring guide β€” Python documentation
The first conventions every Python docstring should follow are defined in PEP-257. As PEP-257 is quite open, and some other standards exist on top of it. In the case of pandas, the numpy docstring convention is followed.
🌐
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.
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
🌐
NumPy
numpy.org β€Ί doc β€Ί stable β€Ί dev β€Ί howto-docs.html
How to contribute to the NumPy documentation β€” NumPy v2.5 Manual
-------------) that sphinx does not expect to find in docstrings. ... Note that for documentation within NumPy, it is not necessary to do import numpy as np at the beginning of an example.
🌐
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 to users.
🌐
Pyansys
dev.docs.pyansys.com β€Ί doc-style β€Ί docstrings.html
Numpydoc docstrings β€” PyAnsys developer's guide
Because you use the same markup in docstrings as you do in RST files, see Quick reStructuredText for a markup summary. Surround any text that you want to set apart as literal text (code entities) in double backticks to render it in a monospaced font within a gray box. Use double backticks to surround the names of files, folders, classes, methods, and variables. ... While the numpydoc ...
🌐
NumPy
numpy.org β€Ί devdocs β€Ί dev β€Ί howto-docs.html
How to contribute to the NumPy documentation β€” NumPy v2.5.dev0 Manual
-------------) that sphinx does not expect to find in docstrings. ... Note that for documentation within NumPy, it is not necessary to do import numpy as np at the beginning of an example.
🌐
Readthedocs
pydoctor.readthedocs.io β€Ί en β€Ί latest β€Ί docformat β€Ί google-numpy.html
Google and Numpy β€” pydoctor documentation - Read the Docs
The main difference between the two styles is that Google uses indentation to separate sections, whereas NumPy uses underlines. This means that 2 blank lines are needed to end a NumPy section that is followed by a regular paragraph (i.e.