This release is a pre-release and may not be stable for production use.
docstring_parser
Parse Python docstrings. Currently support ReST, Google, Numpydoc-style and Epydoc docstrings.
Example usage:
>>> from docstring_parser import parse
>>>
>>>
>>> docstring = parse(
... '''
... Short description
...
... Long description spanning multiple lines
... - First line
... - Second line
... - Third line
...
... :param name: description 1
... :param int priority: description 2
... :param str sender: description 3
... :raises ValueError: if name is invalid
... ''')
>>>
>>> docstring.long_description
'Long description spanning multiple lines\n- First line\n- Second line\n- Third line'
>>> docstring.params[1].arg_name
'priority'
>>> docstring.raises[0].type_name
'ValueError'
parse() raises ParseError on a docstring it cannot read. try_parse()
never raises for the docstring's text. It keeps what it can read, puts the text of the rest in the long
description, and lists a problem for each part, with its line:
>>> from docstring_parser import try_parse
>>>
>>> result = try_parse(
... "Short.\n\nArgs:\n x (int) the x.\n y: Y.\n", "google"
... )
>>> result.docstring.params[0].arg_name
'y'
>>> result.problems
[Problem(line=4, code='missing-colon', message="Expected a colon in 'x (int) the x.'.")]
A problem's code names what is wrong and stays the same between versions,
while its message may change. The Problem class documents every code.
Read API Documentation. BEHAVIOR.md states what the output promises and lists every problem code, and MIGRATING.md says what to change for each breaking change since 0.18.
Custom sections
Every style recognises a list of sections, or for ReST and Epydoc, fields.
A SectionSpec declares one: the titles that start it, the kind of items in
it and, optionally, the key each item records. Pass a
list as sections to parse(), to parse_from_object() or to a style's
parser. It replaces the style's own list, which default_sections(style)
returns, so start from that to add to it:
>>> from docstring_parser import DocstringStyle, parse
>>> from docstring_parser.sections import Kind, SectionSpec, default_sections
>>>
>>> sections = [
... *default_sections(DocstringStyle.GOOGLE),
... SectionSpec("Kwargs", Kind.KEYWORD),
... SectionSpec("C++ Notes", Kind.TEXT),
... ]
>>> docstring = parse(
... '''
... Short description
...
... Kwargs:
... timeout (float): seconds to wait
... ''',
... sections=sections,
... )
>>> param = docstring.params[0]
>>> param.kind, param.key, param.arg_name, param.type_name
(<Kind.KEYWORD: 2>, 'keyword', 'timeout', 'float')
- Titles are matched as written, so they may hold any characters, such as
C++ NotesorArgs (old). List every spelling to accept, such asARGSnext toArgs. bare=Truemarks a title that stands alone on its line: with no colon after it in Google, or no underline below it in Numpydoc.- In ReST and Epydoc, titles are field names:
SectionSpec("input", Kind.PARAM)reads:input x:and@input x:as params. parse_itemis a function that gets the meta of each item of the section, already split into its name, type and description. It may change the meta and return None, or return the meta to use instead.
parse() finds a parser built for the sections it is given. To parse many
docstrings, a parser can also be built once and used directly: each style's
module has a Parser, as do docstring_parser.auto for telling the style,
and each takes sections and has a parse(text) method:
>>> from docstring_parser import google
>>>
>>> parser = google.Parser(sections)
>>> parser.parse("Short.\n\nKwargs:\n timeout (float): seconds").params[0].key
'keyword'
These replace the ways parsers used to be customised by overriding their internals; MIGRATING.md lists what replaces each.
Installation
Installation using pip
pip install docstring_parser
# or if you want to install it in a virtual environment
python -m venv venv # create environment
source venv/bin/activate # activate environment
python -m pip install docstring_parser
Installation using conda
- Download and install miniconda or anaconda
- Install the package from the conda-forge channel via:
conda install -c conda-forge docstring_parser- or create a new conda environment via
conda create -n my-new-environment -c conda-forge docstring_parser
Contributing
To set up the project:
git clone https://github.com/rr-/docstring_parser.git
cd docstring_parser
uv sync # create .venv with the dev dependencies
uv run prek install # set up the lint and message hooks
To run tests:
uv run pytest
The justfile wraps these and other common tasks; run just to list them.
Metadata
Release files for docstring-parser 1.0.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| docstring_parser-1.0.0a1.tar.gz | 723.9 kB | With provenance | Details for docstring_parser-1.0.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| docstring_parser-1.0.0a1-py3-none-any.whl | Python 3 | none | any | Details for docstring_parser-1.0.0a1-py3-none-any.whl |
Total release size: 791.5 kB
Release files / docstring_parser-1.0.0a1.tar.gz
| Download URL | docstring_parser-1.0.0a1.tar.gz |
|---|---|
| Size | 723.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a547e690a378ed57e8ea15a83e073c6f9475d8a7b20ea7f85c4f770daf90b909
|
|
BLAKE2b-256 checksum How to use checksums |
4fd896e45e342a0e550d495edbd1ab08a91a60f0c0383a1fd196dd6db0c5a6ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logRelease files / docstring_parser-1.0.0a1-py3-none-any.whl
| Download URL | docstring_parser-1.0.0a1-py3-none-any.whl |
|---|---|
| Size | 67.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a89c48f10f72c9d9151fae9c1517f3941ee8d0d5bd8bef62c096856f9d9d176d
|
|
BLAKE2b-256 checksum How to use checksums |
fd61fb8012e346e120c183b755909ace47d262d57ca01e1947f0e8bf619f0bf3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logSecurity for docstring-parser 1.0.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for docstring_parser-1.0.0a1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 1, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.