docstring-parser

raw JSON →
0.17.0 verified Tue May 12 auth: no python install: verified quickstart: verified

A Python library for parsing docstrings in reST, Google, and Numpydoc formats. Current version: 0.17.0, released on July 21, 2025. Maintained with a stable release cadence.

pip install docstring-parser
error ModuleNotFoundError: No module named 'docstring_parser'
cause The 'docstring_parser' library has not been installed in the current Python environment.
fix
Install the library using pip: pip install docstring-parser
error ImportError: cannot import name 'DocstringAttr' from 'docstring_parser.common'
cause This error typically occurs due to incompatible versions of `docstring-parser` or conflicts with a `docstring-parser-fork` package, where the expected class `DocstringAttr` may not exist or has been renamed in the installed version.
fix
Ensure only one version of docstring-parser (and no conflicting forks) is installed and that it's up to date. Uninstall conflicting packages and reinstall docstring-parser.
error ValueError: not enough values to unpack (expected 2, got 1)
cause The docstring being parsed, particularly in Google style (e.g., in an `Args:` section), has a malformed entry where a colon (':') is expected but another character (like a hyphen '-') is found, causing the `split` operation to fail.
fix
Correct the docstring format to adhere strictly to the expected style, ensuring parameters are defined with a colon, e.g., param_name: description.
error ValueError: Arg X in docstring not found in function signature
cause A parameter is documented in the function's docstring (e.g., using `@param` or `Args:`) but does not actually exist in the function's definition (its signature).
fix
Either add the missing parameter to the function's signature or remove its documentation from the docstring to match the actual function definition.
breaking In version 0.17.0, the 'parse' function now requires the 'style' parameter to be explicitly set. Omitting it will raise a TypeError.
fix Update function calls to include the 'style' parameter, e.g., 'parse(docstring, style=DocstringStyle.AUTO)'.
deprecated The 'parse_from_object' function is deprecated and will be removed in a future release. Use 'parse' with the appropriate style parameter instead.
fix Replace calls to 'parse_from_object' with 'parse' and specify the 'style' parameter.
gotcha When parsing docstrings with the 'parse' function, ensure that the 'style' parameter matches the docstring format (e.g., 'reST', 'Google', 'Numpydoc') to avoid parsing errors.
fix Always specify the correct 'style' parameter when calling 'parse'.
python os / libc status wheel install import disk
3.10 alpine (musl) - - 0.03s 17.9M
3.10 slim (glibc) - - 0.02s 18M
3.11 alpine (musl) - - 0.07s 19.8M
3.11 slim (glibc) - - 0.05s 20M
3.12 alpine (musl) - - 0.07s 11.7M
3.12 slim (glibc) - - 0.06s 12M
3.13 alpine (musl) - - 0.05s 11.4M
3.13 slim (glibc) - - 0.05s 12M
3.9 alpine (musl) - - 0.03s 17.4M
3.9 slim (glibc) - - 0.02s 18M

A quickstart guide demonstrating how to parse a sample docstring using the 'parse' function from docstring_parser.

from docstring_parser import parse

# Sample docstring
docstring = """
This is a sample function.

:param x: The input value
:type x: int
:return: The squared value of x
:rtype: int
"""

# Parse the docstring
parsed = parse(docstring)

# Access parsed components
print(f"Description: {parsed.short_description}")
print(f"Parameters: {parsed.params}")
print(f"Returns: {parsed.returns}")