docformatter
Formats docstrings to follow PEP 257
What it is and what it does
docformatter is a command-line tool and library that automatically reformats Python docstrings to follow PEP 257 conventions. It enforces consistent triple-quote usage, proper line breaks between summary and description, correct placement of closing quotes, and removal of trailing whitespace. It also supports Sphinx and Epytext field list styles and can be configured to work alongside black for code formatting.
The tool is designed for developers and teams who want to standardize docstring formatting across a codebase without manual editing. It works as both a standalone CLI (with --in-place file modification) and as a library that can be integrated into linting pipelines. The package has minimal dependencies and supports current Python versions, making it straightforward to add to existing projects.
Use it for:
- Enforce PEP 257 docstring standards across a team's Python codebase automatically.
- Integrate into pre-commit hooks or CI/CD pipelines to catch docstring formatting issues before merge.
- Reformat legacy codebases with inconsistent docstring styles to a uniform standard.
- Work alongside black to ensure both code and docstring formatting align with project conventions.
- Configure project-wide docstring rules via pyproject.toml for reproducible formatting.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Automatically formats Python docstrings to comply with PEP 257 conventions, including proper quote usage, line breaks, and field list formatting.
Yes. docformatter is actively maintained, has no known vulnerabilities, minimal dependencies, and solves a real problem in code standardization. It integrates well with existing Python tooling and is permissively licensed. Install it if your team values consistent docstring formatting or you need PEP 257 compliance automation.
Install
docformatter on PyPI
pip
pip install docformatteruv
uv add docformatterpoetry
poetry add docformatterInstalling docformatter
Before you install
Low friction: pure Python wheel with a single runtime dependency (charset_normalizer). Active maintenance with a recent release (108 days ago) and ongoing commits. Supports modern Python versions (3.10–3.14) and PyPy.
License in practice
Licensed under Expat (MIT), a permissive license that allows commercial and private use with minimal restrictions. No licensing barriers to adoption.
Quickstart
pip install docformatter
# Format a file in-place
docformatter --in-place example.py
# Or use as a library
from docformatter import format_docstring
formatted = format_docstring('', '"""Original docstring."""')
Requires Python 3.10 or later; Python < 3.11 users need the optional tomli extra to use pyproject.toml configuration.
Verify before relying
- Whether the package handles all Sphinx and Epytext field list styles or only a subset.
- Performance characteristics when formatting large codebases or deeply nested docstrings.
- Compatibility guarantees with other formatters beyond black when using --black mode.
Package facts
| License | Expat (permissive) |
| Python support | supports the current Python release (<4.0,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — charset_normalizer |
| Maintenance | actively maintained — 108 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,476,184/month — #3,859 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: docformatter-1.7.8-py3-none-any.whl
Keywords: PEP 257, pep257, style, formatter, docstrings
Tags
More Quality Assurance packages
Coverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
ruffRuff is a Python linter and code formatter…
permissive · top 1,000 on PyPI
pexpectPexpect spawns and controls interactive console…
permissive · top 1,000 on PyPI
blackBlack reformats Python source code to a…
permissive · top 1,000 on PyPI
pytest-xdistpytest-xdist distributes pytest tests across…
permissive · top 1,000 on PyPI
cfn-lintValidates AWS CloudFormation templates in YAML…
permissive · top 1,000 on PyPI
pydocstringformatterAutomatically formats Python docstrings to…
permissive · top 15,000 on PyPI
attributes-docExtracts and stores docstrings for class…
permissive · top 15,000 on PyPI
pydocstylepydocstyle is a static analysis tool that…
permissive · top 5,000 on PyPI
flake8-docstringsIntegrates pydocstyle docstring checking into…
permissive · top 5,000 on PyPI
docstr-coverageMeasures docstring coverage in Python source…
permissive · top 15,000 on PyPI
docstring-parserParses Python docstrings in ReST, Google,…
permissive · top 1,000 on PyPI
flake8-quotesA flake8 plugin that enforces consistent quote…
permissive · top 5,000 on PyPI
numpydocA Sphinx extension that parses and renders…
permissive · top 5,000 on PyPI
reformat-gherkinAutomatically formats Gherkin feature files to…
permissive · top 15,000 on PyPI
pylint-quotesA Pylint plugin that enforces consistent use of…
permissive · top 15,000 on PyPI