Skip to main content

Docstringify

Flag missing docstrings and, optionally, generate them from signatures and type annotations.

Last Release PyPI release Supported Python Versions License
Build status CI
Downloads PyPI downloads

About

Given a file, test.py, with the following contents:

def say_hello(name: str = 'World') -> None:
    print(f'Hello, {name}!')

You can use Docstringify in three modes:

  1. check – Flag missing docstrings:

    test is missing a docstring
    test.say_hello is missing a docstring
    
  2. suggest – Suggest docstring templates based on type annotations:

    test is missing a docstring
    Hint:
    """__description__"""
    
    test.say_hello is missing a docstring
    Hint:
    """
    __description__
    
    Parameters
    ----------
    name : str, default="World"
        __description__
    """
    
  3. edit – Add docstring templates to source code files:

    """__description__"""
    
    
    def say_hello(name: str = 'World') -> None:
        """
        __description__
    
        Parameters
        ----------
        name : str, default="World"
            __description__
        """
        print(f'Hello, {name}!')
    

Usage

Pre-commit hook

Check mode: docstringify-check

Add the following to your .pre-commit-config.yaml file to block commits with missing docstrings before any formatters like ruff:

- repo: https://github.com/stefmolin/docstringify
  rev: <version>
  hooks:
    - id: docstringify-check

By default, all docstrings are required. If you want to be more lenient, you can set the threshold, which is the percentage of docstrings that must be present:

- repo: https://github.com/stefmolin/docstringify
  rev: <version>
  hooks:
    - id: docstringify-check
      args: [--threshold=0.75]

Suggest mode: docstringify-suggest

If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), use the suggest mode, along with the docstring style you want to use (options are google, numpydoc, and stub). Here, we ask for stub suggestions (just single lines of """__description__"""):

- repo: https://github.com/stefmolin/docstringify
  rev: <version>
  hooks:
    - id: docstringify-suggest
      args: [--style=stub]

Edit mode: docstringify-edit

Use the edit mode to create a copy of each file with docstring templates. Here, we ask for changes using the Google docstring style:

- repo: https://github.com/stefmolin/docstringify
  rev: <version>
  hooks:
    - id: docstringify-edit
      args: [--style=google]

If you want the changes to be made in place, add --overwrite. Here, we ask for numpydoc-style docstring suggestions:

- repo: https://github.com/stefmolin/docstringify
  rev: <version>
  hooks:
    - id: docstringify-edit
      args: [--overwrite, --style=numpydoc]

Be sure to check out the pre-commit documentation for additional configuration options.

Command line

First, install the docstringify package from PyPI:

$ python -m pip install docstringify

Then, use the docstringify entry point on the file(s) of your choice. For example, to run in check mode:

$ docstringify check /path/to/file [/path/to/another/file]

Run docstringify --help for more information.

Python

First, install the docstringify package from PyPI:

$ python -m pip install docstringify

Then, use the DocstringVisitor() class on individual files to see spots where docstrings are missing:

>>> from docstringify.traversal import DocstringVisitor
>>> visitor = DocstringVisitor('test.py')
>>> visitor.process_file()
test is missing a docstring
test.say_hello is missing a docstring

If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide a converter:

>>> from docstringify.converters import NumpydocDocstringConverter
>>> from docstringify.traversal import DocstringVisitor
>>> visitor = DocstringVisitor('test.py', converter=NumpydocDocstringConverter)
>>> visitor.process_file()
test is missing a docstring
Hint:
"""__description__"""

test.say_hello is missing a docstring
Hint:
"""
__description__

Parameters
----------
name : str, default="World"
    __description__
"""

To make changes to your files, you will need to use the DocstringTransformer instead. With the DocstringTransformer, the converter is required:

>>> from docstringify.converters import GoogleDocstringConverter
>>> from docstringify.traversal import DocstringTransformer
>>> transformer = DocstringTransformer('test.py', converter=GoogleDocstringConverter)
>>> transformer.process_file()
test is missing a docstring
test.say_hello is missing a docstring
Docstring templates written to /.../test_docstringify.py

If you want to overwrite the file with the edits, pass overwrite=True to DocstringTransformer():

>>> from docstringify.converters import GoogleDocstringConverter
>>> from docstringify.traversal import DocstringTransformer
>>> transformer = DocstringTransformer(
...     'test.py', converter=GoogleDocstringConverter, overwrite=True
... )
>>> transformer.process_file()
test is missing a docstring
test.say_hello is missing a docstring
Docstring templates written to /.../test.py

Contributing

Please consult the contributing guidelines.

Metadata

Release files for docstringify 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for docstringify 2.0.1
File Size Uploaded
docstringify-2.0.1.tar.gz 49.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for docstringify 2.0.1
File Interpreter ABI Platform
docstringify-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 73.8 kB

Release files / docstringify-2.0.1.tar.gz

Download URL docstringify-2.0.1.tar.gz
Size 49.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c2e5e612b65cfc2e0809531100c3d1a4bcc15d1f92269917d6613cf0c2dda39c
BLAKE2b-256 checksum
How to use checksums
5e499b6cb305a82a52de18e4a5516f51315274ab7a56a660f3a17d217a27f73a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 17, 2026.

Transparency log

Release files / docstringify-2.0.1-py3-none-any.whl

Download URL docstringify-2.0.1-py3-none-any.whl
Size 24.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99923d8360b4682ed94ce83d973c253af3e75d04809c1db7b3a3423a715a06ef
BLAKE2b-256 checksum
How to use checksums
236529056f1279d7591d8a1670acd277a0d8ce55301f00cfe8c776b685f66bf0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 17, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page