Skip to main content

rstformat

A formatter for reStructuredText files.

Become a Sponsor PyPI PyPI Downloads Python Versions GitHub license

An open source and free formatter for reStructuredText (.rst) files, distributed under the MIT License.

Features

Feature Setting
Trim trailing whitespace trim_trailing_whitespace
Output line ending (LF / CRLF / auto-detect) line_ending
Resize section adornments to title width normalize_section_underlines
Add/remove blank lines around headings normalize_section_spacing
Limit consecutive blank lines max_consecutive_blank_lines
Insert final newline insert_final_newline
East-Asian double-width character support (implicit)

Plugin system for delegating embedded code-block formatting to language-specific tools:

  • Python code blocks → Black or Ruff formatter
  • Shell script blocks → shfmt formatter
  • SQL blocks → sqlfluff formatter (planned)

Installation

Install from PyPI:

pip install rstformat

Or with uv:

uv tool install rstformat

To enable optional features:

pip install rstformat[editorconfig]  # Honor .editorconfig settings
pip install rstformat[lint]          # Pre-flight validation via docutils/rstcheck
pip install rstformat[dev]           # Development dependencies (tests, ruff)

Usage

Format files in-place:

rstformat file.rst dir/

Check mode (exit 1 if any file would change):

rstformat --check file.rst

Show unified diff without writing:

rstformat --diff file.rst

Read from stdin, write to stdout:

echo "Title\n=====" | rstformat

Control output line endings:

rstformat --line-ending crlf file.rst    # Force Windows (CRLF)
rstformat --line-ending auto file.rst    # Preserve input style

For all options, run:

rstformat --help

Configuration

Create pyproject.toml or .rstfmt.toml in your project:

[tool.rstformat]
adornments            = "#*=-^\"'`:.~_+"
insert_final_newline  = true
line_ending           = "lf"   # "lf" | "crlf" | "auto"
max_consecutive_blank_lines = 2
normalize_section_spacing   = true
normalize_section_underlines = true
trim_trailing_whitespace     = true

rstformat also respects .editorconfig for compatible settings:

[*.rst]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

For more details, see DESIGN.md.

Documentation

License

Copyright (c) 2026 LeXtudio Inc.

Licensed under the MIT License. See LICENSE for details.

Community

Metadata

Release files for rstformat 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rstformat 0.1.0
File Size Uploaded
rstformat-0.1.0.tar.gz 50.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rstformat 0.1.0
File Interpreter ABI Platform
rstformat-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 60.5 kB

Release files / rstformat-0.1.0.tar.gz

Download URL rstformat-0.1.0.tar.gz
Size 50.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3ea351cdc32c0a9b758e7ac5c6797e8aab690cac2f208c2f91b587a80fdd625c
BLAKE2b-256 checksum
How to use checksums
cb3dafab4ac0f292b1c43bc87fb26e5ad11a1eb654f3945c506b5c81f8fe889a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.5

Release files / rstformat-0.1.0-py3-none-any.whl

Download URL rstformat-0.1.0-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc9681529bcd4caeffff36393088f97895a85018fe9586a8265b64b1fa311455
BLAKE2b-256 checksum
How to use checksums
8dc73752296639c05e7402c7bbb2bc8e0fdedad56444bd3e3d24918b07d1d979
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.9.5

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page