Skip to main content

Not to be confused with rustfmt.

Description

rstfmt is a tool for automatically formatting reStructuredText files in a consistent way.

Like Black and gofmt, the motivation is to provide a format that is reasonable and minimally configurable to prevent teams from wasting time on style discussions (or individuals on manually doing formatting, for that matter).

Currently, rstfmt is in an early stage of development. Not all reST constructs are covered and the interface or formatting may change at any time without warning.

To get a feel for the output of rstfmt, see the sample file.

Usage

# Install directly from the repository.
pip install git+https://github.com/dzhu/rstfmt

# Install from PyPI.
pip install rstfmt

# Read a file from stdin and write the formatted version to stdout.
rstfmt

# Don't edit any files; exit with a nonzero status code if any files are not formatted.
rstfmt --check <file>...

# Print diffs for all files that are not formatted (implies --check).
rstfmt --diff <file>...

# Format the given files in place.
rstfmt <file>...

# Format all files with the `rst` or `txt` extension inside a directory.
rstfmt <directory>...
rstfmt --ext txt <directory>...

# Wrap paragraphs to the given line length (default 72).
rstfmt -w <width>

Like Black’s blackd, there is also a daemon that provides formatting via HTTP requests to avoid the cost of starting and importing everything on every run.

# Install.
pip install 'git+https://github.com/dzhu/rstfmt#egg=rstfmt[d]'
pip install 'rstfmt[d]'

# Start the daemon (binds to localhost:5219 by default).
rstfmtd --bind-host=<host> --bind-port=<port>

# Print the formatted version of a file.
curl http://locahost:5219 --data-binary @<file>

# Specify the line length (default 72).
curl -H 'X-Line-Length: 72' http://locahost:5219 --data-binary @<file>

# Mimic the standalone tool: read from stdin, write to stdout, exit with
# a nonzero status code if there are errors.
curl -fsS http://locahost:5219 --data-binary @/dev/stdin

With editors

The default behavior of reading from stdin and writing to stdout should integrate well with other systems, such as on-save hooks in editors. For example, here’s a configuration for reformatter.el, including both standalone and daemon modes:

;; Run the standalone tool.
(reformatter-define rstfmt
  :program "rstfmt")
(add-hook 'rst-mode-hook #'rstfmt-on-save-mode)

;; Query the daemon.
(reformatter-define client-rstfmt
  :program "curl"
  :args '("-fsS" "http://localhost:5219" "--data-binary" "@/dev/stdin"))
(add-hook 'rst-mode-hook #'client-rstfmt-on-save-mode)

Metadata

Release files for rstfmt 0.0.14

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

Source distribution (sdist)

Source distribution for rstfmt 0.0.14
File Size Uploaded
rstfmt-0.0.14.tar.gz 22.3 kB Details

Built distribution (wheel)

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

Total release size: 39.7 kB

Release files / rstfmt-0.0.14.tar.gz

Download URL rstfmt-0.0.14.tar.gz
Size 22.3 kB
Tags Source
SHA-256 checksum
How to use checksums
5dd5e6988386f21fd89adc015baca64588c38fa89a87ab691f81c7675162b3d2
BLAKE2b-256 checksum
How to use checksums
a5c7544357eee7b190946bdb92626d0a56ce0c7784a1fc9b04320f95516508d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / rstfmt-0.0.14-py3-none-any.whl

Download URL rstfmt-0.0.14-py3-none-any.whl
Size 17.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5488be45c457239cf512239899caebd5f67bbff562e826fe3eb2059335535b2a
BLAKE2b-256 checksum
How to use checksums
b7d80fd8c425ae8afa1076c98bef8b3916a46046d157ea1b61da1fee62baeeaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.0.14 This release

2 release files

0.0.12

1 release file

0.0.11

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

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