skillfed

ruff-format

Python bindings for the Ruff code formatter, built with Rust and PyO3.

ruff-format v0.5.4 97.9K downloads/30d#13,124 on PyPI1
Permissive license MIT Active released

What it is and what it does

ruff-format is a Python package that wraps Ruff's formatting engine, written in Rust and exposed via PyO3 bindings. It lets you format Python code from within your own Python programs rather than only via the command line. The package provides three main functions: is_valid_syntax to check syntax, parse_code to parse without formatting, and format_string to reformat code with a configurable line width (default 80).

The package has no runtime dependencies and is distributed as prebuilt wheels for most platforms, though it does require Rust to build from source. It supports Python 3.8 through 3.14 and is actively maintained, with recent releases available.

Use it for:

  • Programmatically format code snippets or user-submitted Python in a web application or IDE
  • Integrate code formatting into a custom linting or code review pipeline
  • Format Python code with a specific line width in a build or CI/CD workflow
  • Validate Python syntax before attempting to format or execute it

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Provides Python bindings to Ruff's code formatter, allowing you to format Python code programmatically with configurable line width.

Yes, if you need to format Python code programmatically in your application. The package is actively maintained, has no runtime dependencies, and is backed by Ruff's well-regarded formatter. The medium install friction (compiled bindings) is offset by prebuilt wheels for most platforms. No known security issues.

Install

ruff-format on PyPI

pip

pip install ruff-format

uv

uv add ruff-format

poetry

poetry add ruff-format

Installing ruff-format

Before you install

Medium install friction due to compiled Rust bindings, but prebuilt wheels are available for most platforms. Actively maintained with recent releases.

License in practice

MIT license permits unrestricted use, modification, and distribution with minimal restrictions.

Quickstart

from ruff_format import format_string

code = "def hello(  x,y,   z  ):\n    print( x+y+z )"
formatted = format_string(code)
print(formatted)

Requires Python 3.8 or later; prebuilt wheels available for most platforms, but source builds require Rust and maturin.

Verify before relying

  • Whether format_string handles all Python syntax edge cases or has known limitations
  • Performance comparison with other formatters on large codebases
  • Whether custom formatting rules beyond line_width are supported

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.8)
Install friction medium — platform-specific wheel
Runtime dependencies none
Maintenance actively maintained — 4 days since the last release
Last repo commit
First released
Downloads 97,853/month — #13,124 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: ruff_format-0.5.4-cp314-cp314t-macosx_10_12_x86_64.whl; ruff_format-0.5.4-cp314-cp314t-macosx_11_0_arm64.whl; ruff_format-0.5.4-cp314-cp314t-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; ruff_format-0.5.4-cp314-cp314t-manylinux_2_17_armv7l.manylinux2014_armv7l.whl; ruff_format-0.5.4-cp314-cp314t-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl; ruff_format-0.5.4-cp314-cp314t-manylinux_2_17_s390x.manylinux2014_s390x.whl; ruff_format-0.5.4-cp314-cp314t-manylinux_2_17_x86_64.manylinux2014_x86_64.whl; ruff_format-0.5.4-cp314-cp314t-manylinux_2_5_i686.manylinux1_i686.whl; ruff_format-0.5.4-cp314-cp314t-musllinux_1_2_aarch64.whl; ruff_format-0.5.4-cp314-cp314t-musllinux_1_2_armv7l.whl; ruff_format-0.5.4-cp314-cp314t-musllinux_1_2_i686.whl; ruff_format-0.5.4-cp314-cp314t-musllinux_1_2_x86_64.whl; ruff_format-0.5.4-cp314-cp314t-win32.whl; ruff_format-0.5.4-cp314-cp314t-win_amd64.whl; ruff_format-0.5.4-cp314-cp314t-win_arm64.whl; ruff_format-0.5.4-cp38-abi3-macosx_10_12_x86_64.whl; ruff_format-0.5.4-cp38-abi3-macosx_11_0_arm64.whl; ruff_format-0.5.4-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl; ruff_format-0.5.4-cp38-abi3-manylinux_2_17_armv7l.manylinux2014_armv7l.whl; ruff_format-0.5.4-cp38-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl

Programming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Programming Language :: Python :: Implementation :: CPythonProgramming Language :: Python :: Implementation :: PyPyProgramming Language :: Rust

Tags

python code formatterruff formatter bindingsformat python code programmaticallycode formatting libraryrust-powered formatterformat_string python
code-formattingrust-bindings

More Quality Assurance packages