🌐
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 ...
🌐
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?)

🌐
Readthedocs
sphinxcontrib-napoleon.readthedocs.io
Napoleon - Marching toward legible docstrings — napoleon 0.7 documentation
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 be easier to read for long and in-depth docstrings.
🌐
McGinnis, Will
mcginniscommawill.com › home › mcginnis, will › journal › effective docstrings: google vs. numpy vs. restructuredtext styles
Effective Docstrings: Google vs. NumPy vs. reStructuredText Styles | McGinnis, Will
March 6, 2025 - If you can’t explain what your function will do clearly in the docstring, you might need to rethink your design. Whatever style you choose, you’ll want to make sure Sphinx can parse it. For reST style, you’re already set. For Google or NumPy style, add this to your conf.py:
🌐
Sphinx
sphinx-doc.org › en › master › usage › extensions › napoleon.html
sphinx.ext.napoleon – Support for NumPy and Google style docstrings — Sphinx documentation
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 be easier to read for long and in-depth docstrings.
🌐
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.
🌐
Stack Overflow
stackoverflow.com › questions › 58205800 › which-format-of-docstring-is-the-standard
python - Which format of docstring is the standard? - Stack Overflow
Numpy has specific extensions that work with sphinx and other doc generators. ... It's only a matter of taste, google's docstring has the advantage of being more concise than numpy's (so they tend to be easier to read as text-docstrings).
🌐
Towards Data Science
towardsdatascience.com › home › latest › advanced code documentation beyond comments and docstrings
Advanced Code Documentation Beyond Comments and Docstrings | Towards Data Science
March 5, 2025 - Personally, I prefer Google docstring format as it results in wider docstrings with fewer lines of code. Numpy docstring format tends to result in narrower docstrings with more lines of code.
🌐
Zencoder
zencoder.ai › home › how to choose the right docstring format for your project
How to Choose the Right Docstring Format for Your Project
March 1, 2025 - Use NumPy for scientific computing: For projects heavily involved in data analysis, mathematical computations, or scientific algorithms, NumPy docstrings provide the specialized structure you need.
Find elsewhere
Top answer
1 of 4
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 4
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
🌐
Alwaysdata
bwanamarko.alwaysdata.net › napoleon › format_exception.html
NumPyDoc vs. Sphinx and Google Format — sphinxy 0.1 documentation
Args: etype (str): exception type value (int): exception value tb (traceback): traceback object Keyword Args: limit (int or None): maximum number of stack frames to show [optional] Returns: out: list of strings Raises: AttributeError, KeyError A really great idea. A way you might use me is >>> data = format_exception_google('wow', 999, KeyError) """ return etype, value, tb · On the other hand, I really like the NumPy format.
🌐
GitHub
github.com › SciTools › iris › issues › 3841
Docs build error (google vs numpy docstrings) · Issue #3841 · SciTools/iris
September 11, 2020 - I believe this is due to the Iris code base using Google Style docstrings but the code that is pulled in above is from matplotlib that now uses NumPy docstrings, see https://matplotlib.org/_modules/matplotlib/colors.html#Normalize.process_value. #3840 may resolve this.
Author: SciTools
🌐
Safjan
safjan.com › home › note › python - docstrings styles
Python - Docstrings Styles - Krystian Safjan's Blog
July 11, 2023 - Currently, pure Markdown (with extensions, numpydoc, and Google-style docstrings formats are supported, along with some reST directives.
🌐
GitHub
github.com › amontalenti › elements-of-python-style › issues › 8
Use of numpy style or google style docstrings · Issue #8 · amontalenti/elements-of-python-style
January 4, 2016 - Google style or numpy style docstrings are easier to read in the source code than the "old" Sphinx style. In addition, these "new" docstring styles are supported OTB by the late...
Author: amontalenti
🌐
GitHub
github.com › PyCQA › docformatter › issues › 60
Support numpy or Google docstrings · Issue #60 · PyCQA/docformatter
August 25, 2020 - C: styleRelates to docstring format style (e.g., Google, NumPy, Sphinx)Relates to docstring format style (e.g., Google, NumPy, Sphinx)P: enhancementFeature that is outside the scope of PEP 257Feature that is outside the scope of PEP 257U: lowA relatively low urgency issueA relatively low urgency issue ·
Author: PyCQA
🌐
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 - Choosing the right docstring format is essential for maintaining consistent and readable documentation in your Python code. Whether you opt for Google style, Sphinx/reStructuredText, NumPy style, or Epytext, the key is to maintain consistency within your codebase or project.
🌐
GitHub
gist.github.com › nipunsadvilkar › fec9d2a40f9c83ea7fd97be59261c400
What is the standard Python docstring format? · GitHub
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.
🌐
Real Python
realpython.com › lessons › comparing-common-docstring-styles
Comparing Common Python Docstring Styles (Video) – Real Python
05:23 So if your work is scientific in nature, data-related, or depends heavily on similar such libraries, the NumPy style would be a great choice for your docstrings.
Published: February 17, 2026