docstrfmt
docstrfmt: A formatter for Sphinx flavored reStructuredText.
What it is and what it does
docstrfmt is a command-line tool that automatically formats reStructuredText markup and Python docstrings to a consistent, opinionated style. It draws inspiration from Black and rstfmt, aiming to reduce style discussions and manual formatting work by enforcing a single reasonable format. The tool reads Python files or raw reStructuredText and rewrites docstrings and markup according to its rules, with configurable line length that defaults to Black's 88 characters or can be read from pyproject.toml.
The package depends on Black, libcst, docutils, Sphinx, and related utilities to parse and reformat the text. It runs as a command-line tool or optionally as an HTTP daemon (docstrfmtd) to avoid repeated startup costs. Currently in beta, it covers most common reStructuredText constructs but acknowledges gaps in coverage for less common syntax.
Use it for:
- Enforce consistent docstring formatting across a Python project's codebase automatically.
- Integrate docstring formatting into pre-commit hooks to catch style issues before commit.
- Format standalone reStructuredText files (e.g., documentation, README files) to match project conventions.
- Run as a daemon service to format docstrings on-demand via HTTP in editor plugins or CI pipelines.
- Migrate existing docstrings to a standardized format without manual editing.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Automatically formats reStructuredText in files and Python docstrings to a consistent style, similar to how Black formats Python code.
Yes, if you work with reStructuredText or Sphinx-style docstrings and want automated, opinionated formatting. The low install friction, active maintenance, permissive license, and zero known vulnerabilities make it a safe choice. The beta status and acknowledged gaps in construct coverage are worth noting if you rely on advanced reStructuredText features, but for typical docstrings and markup it is stable and ready to use.
Install
docstrfmt on PyPI
pip
pip install docstrfmtuv
uv add docstrfmtpoetry
poetry add docstrfmtInstalling docstrfmt
Before you install
Low friction: pure Python wheel with no compiled dependencies. Active maintenance, last commit 2026-08-10, and the project is in beta but described as mostly stable.
License in practice
Permissive license (MIT) means you can use, modify, and distribute this package freely in commercial and private projects without significant restrictions.
Quickstart
pip install docstrfmt
docstrfmt myfile.py
# or read from stdin and write to stdout:
cat myfile.py | docstrfmt
Requires Python 3.10 or later.
Verify before relying
- Coverage of less common reStructuredText constructs beyond the most common ones mentioned as currently supported.
- Performance characteristics when formatting large files or many files in batch.
- Stability guarantees or breaking-change policy given the beta status.
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 12 — black, click, coverage, docutils, docutils-stubs, libcst, platformdirs, roman, sphinx, tabulate, tomli, types-docutils |
| Maintenance | actively maintained — 54 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 81,877/month — #14,194 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: docstrfmt-2.2.0-py3-none-any.whl
Keywords: black, docutils, autoformatter, formatter, lint, restructuredtext, rst, sphinx
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
rich-rstRenders reStructuredText documents as Rich…
permissive · top 1,000 on PyPI
sphinx-lintSphinx Lint checks reStructuredText and Python…
permissive · top 15,000 on PyPI
esbonioA Language Server Protocol implementation for…
permissive · top 15,000 on PyPI
restructuredtext-lintLints reStructuredText documents for structural…
permissive · top 5,000 on PyPI
rstcheckValidates reStructuredText syntax and checks…
permissive · top 5,000 on PyPI
flake8-rst-docstringsA flake8 plugin that validates Python…
permissive · top 15,000 on PyPI
blacken-docsApplies Black code formatting to Python code…
permissive · top 15,000 on PyPI
docstring-to-markdownConverts Python docstrings from…
copyleft · top 5,000 on PyPI
doc8doc8 is a style checker for reStructuredText…
permissive · top 5,000 on PyPI
rstcheck-coreValidates reStructuredText syntax and checks…
permissive · top 5,000 on PyPI