interrogate
interrogate checks your Python codebase for missing docstrings. It aims to make documentation as important as code itself by highlighting methods, functions, classes, and modules that lack docstrings. This tool, currently at version 1.7.0, helps developers understand docstring coverage, enforce documentation in CI/CD pipelines, and assess code quality and maintainability. It supports Python 3.8 and above, with a moderate release cadence.
Warnings
- gotcha By default, `interrogate` enforces an 80% documentation coverage threshold, meaning it will exit with a non-zero status code if your project falls below this. This might unexpectedly fail CI/CD pipelines if not anticipated.
- gotcha Many projects omit docstrings for `__init__` methods. By default, `interrogate` includes these in its coverage calculation. This can lead to lower reported coverage than expected.
- gotcha Generating PNG format badges requires installing `interrogate` with the `[png]` extra (`pip install interrogate[png]`), which in turn depends on `cairosvg`. `cairosvg` often has external system dependencies like `cairo` and `libffi` that must be installed manually (e.g., via Homebrew on macOS or package managers on Linux) and can be complex on Windows.
- gotcha `interrogate` supports configuration via `pyproject.toml` (under `[tool.interrogate]`) or `setup.cfg` (under `[interrogate]`). Users sometimes only rely on command-line flags, missing the opportunity for project-wide, version-controlled settings.
Install
-
pip install interrogate -
pip install interrogate[png]
Imports
- interrogate
interrogate [OPTIONS] [PATHS]...
Quickstart
mkdir my_project
cd my_project
cat <<EOF > my_module.py
"""A module-level docstring."""
def my_function(a, b):
# Missing docstring
return a + b
class MyClass:
"""A class with a docstring."""
def __init__(self):
# Missing __init__ docstring
pass
def my_method(self):
"""A method with a docstring."""
pass
EOF
# Run interrogate with default settings (fail-under 80%)
interrogate my_module.py
# Run with verbose output to see details of missing docstrings
interrogate -vv my_module.py
# Run and ignore __init__ methods, and set a custom fail-under percentage
interrogate --ignore-init-method --fail-under 100 my_module.py