docstring-parser
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.
Warnings
- breaking In version 0.17.0, the 'parse' function now requires the 'style' parameter to be explicitly set. Omitting it will raise a TypeError.
- deprecated The 'parse_from_object' function is deprecated and will be removed in a future release. Use 'parse' with the appropriate style parameter instead.
- 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.
Install
-
pip install docstring-parser
Imports
- parse
from docstring_parser import parse
Quickstart
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}")