ruff-format
Python bindings for the Ruff code formatter, built with Rust and PyO3.
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-formatuv
uv add ruff-formatpoetry
poetry add ruff-formatInstalling 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
Tags
More Quality Assurance packages
Coverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
ruffRuff is a Python linter and code formatter…
permissive · top 1,000 on PyPI
pexpectPexpect spawns and controls interactive console…
permissive · top 1,000 on PyPI
blackBlack reformats Python source code to a…
permissive · top 1,000 on PyPI
pytest-xdistpytest-xdist distributes pytest tests across…
permissive · top 1,000 on PyPI
cfn-lintValidates AWS CloudFormation templates in YAML…
permissive · top 1,000 on PyPI
fable-libraryFable Library for Python provides runtime…
permissive · top 15,000 on PyPI
mdformat-ruffIntegrates ruff code formatting into mdformat…
permissive · top 15,000 on PyPI
stretchablestretchable is a Python layout engine that…
permissive · top 15,000 on PyPI
pytest-ruffA pytest plugin that integrates ruff code…
unclear · top 15,000 on PyPI
darkerDarker reformats Python source code in Git…
permissive · top 15,000 on PyPI
ruff-lspProvides a Language Server Protocol bridge to…
permissive · top 15,000 on PyPI
ast-serializeParses Python source files and serializes their…
permissive · top 1,000 on PyPI
dprint-pydprint-py is a Python wrapper for dprint, a…
permissive · top 15,000 on PyPI