A flake8 plugin that runs the black code formatter's check mode, reporting formatting differences as flake8 BLK violations.
PyCQA/docformatter
A Python command-line tool that automatically reformats docstrings to follow PEP 257 conventions.
- Stars
- 600
- Forks
- 99
- Open issues
- 22
- Last commit
- 4 days ago
What is it?
docformatter is a command-line tool for Python that rewrites docstrings so they follow a subset of the PEP 257 conventions. It normalizes quote style, moves the closing quotes onto their own line for multi-line docstrings, separates the summary from the description with a blank line, and removes stray indentation and trailing whitespace.
It can be run in place on individual files or across a project, and it supports a black-compatible mode via the --black option. It also formats field lists written in Epytext or Sphinx styles. Configuration can be read from pyproject.toml, which uses the standard library tomllib on Python 3.11 and later.
Developers who want consistent docstrings across a codebase without editing each one by hand will find it useful, especially when it runs as part of a lint or pre-commit step.
Key features
- 01Reformats docstrings to follow PEP 257 quoting and layout rules.
- 02Supports black-compatible output via the --black option.
- 03Formats Epytext and Sphinx style field lists.
- 04Can edit files in place with --in-place.
- 05Reads settings from pyproject.toml.
Use cases
- Standardizing docstring formatting across a Python project.
- Enforcing consistent docstrings automatically in a pre-commit hook or CI check.
- Cleaning up legacy code with inconsistent docstring quotes and indentation.
Quick start
- 1
Install docformatter from PyPI with pip
pip install --upgrade docformatter - 2
Format a file's docstrings in place
docformatter --in-place example.py
In collections
Topics
FAQ
- What is docformatter?
- A Python command-line tool that automatically reformats docstrings to follow PEP 257 conventions. docformatter is a command-line tool for Python that rewrites docstrings so they follow a subset of the PEP 257 conventions. It normalizes quote style, moves the closing quotes onto their own line for multi-line docstrings, separates the summary from the description with a blank line, and removes stray indentation and trailing whitespace.
- Is docformatter free to use? What license does it have?
- docformatter is open source under the MIT license. Check the license terms before using it in commercial products.
- Is docformatter still maintained?
- Actively maintained. The last commit to docformatter was on Nov 3, 2026.
- What can I use docformatter for?
- Standardizing docstring formatting across a Python project. Enforcing consistent docstrings automatically in a pre-commit hook or CI check. Cleaning up legacy code with inconsistent docstring quotes and indentation.
- How do I install docformatter?
- Install docformatter from PyPI with pip: pip install --upgrade docformatter Format a file's docstrings in place: docformatter --in-place example.py
- Where can I get docformatter?
- The source code and installation instructions are on GitHub: https://github.com/PyCQA/docformatter
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
A Python CLI that measures how many functions, classes, methods and modules in a codebase have docstrings, with CI-friendly pass/fail thresholds.
A Python code formatter that reformats source files to a configurable style, based on clang-format's layout algorithm.
A Python utility and library that automatically sorts and groups your import statements.
A set of flake8 plugins that check Python code against the OpenStack style guide.
A PHP command-line tool that automatically fixes code to follow PHP coding standards such as PER-CS and Symfony.