Docstr-coverage

2.3.2 · active · verified Fri Apr 17

docstr-coverage is a Python utility that scans source files to ensure proper documentation. It identifies missing docstrings, provides a detailed report, and calculates an overall docstring coverage percentage. The current version is 2.3.2, and it follows an infrequent but active release cadence, typically releasing minor versions a few times a year.

Common errors

Warnings

Install

Imports

Quickstart

The primary usage of docstr-coverage is via the command line, but it also exposes a programmatic API. This example demonstrates how to use `get_docstr_coverage` to analyze a Python file and print the results. For CLI usage, simply run `docstr-coverage your_project/`.

import os
from docstr_coverage import get_docstr_coverage

# Create a dummy file for demonstration
with open('example_module.py', 'w') as f:
    f.write("""""""Module docstring."""\n
class MyClass:\n    """Class docstring."""\n    def __init__(self):\n        # No docstring here - this will be reported\n        pass\n\n    def my_method(self, arg):\n        """Method docstring."""\n        return arg * 2\n""")

# Run docstr-coverage programmatically
report = get_docstr_coverage(
    paths=['example_module.py'],
    skip_init=False,
    skip_magic=True,
    skip_private=False,
    skip_class_innards=False,
    verbose=2
)

print(f"\nOverall coverage: {report['overall_coverage']:.2f}%")

if report['missing_docstrings']:
    print("\nMissing docstrings found:")
    for item in report['missing_docstrings']:
        print(f"  - {item['file']}:{item['line']} ({item['name']}) -> {item['type']}")

# Clean up dummy file
os.remove('example_module.py')

view raw JSON →