A fast Python code formatter powered by Ruff's formatting engine.
ruff-format is a Python package that provides Python bindings to Ruff's Python formatter.
pip install ruff-formatfrom ruff_format import format_string, is_valid_syntax, parse_code
code = """
def hello( x,y, z ):
print( x+y+z )
"""
# Check if code has valid syntax
assert is_valid_syntax(code)
# Parse code (raises RuntimeError on syntax errors)
parse_code(code)
# Format code (default line width: 80)
formatted = format_string(code)
print(formatted)
# Format with a custom line width
formatted = format_string(code, line_width=120)
print(formatted)- Rust (latest stable)
- Python 3.8+
- maturin
# Install maturin
pip install maturin
# Build the package
maturin develop
# Or build a release version
maturin build --releaseMIT