Skip to content

Latest commit

 

History

History
68 lines (45 loc) · 1.14 KB

File metadata and controls

68 lines (45 loc) · 1.14 KB

ruff-format

A fast Python code formatter powered by Ruff's formatting engine.

Overview

ruff-format is a Python package that provides Python bindings to Ruff's Python formatter.

Installation

pip install ruff-format

Usage

from 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)

Development

Prerequisites

  • Rust (latest stable)
  • Python 3.8+
  • maturin

Building from source

# Install maturin
pip install maturin

# Build the package
maturin develop

# Or build a release version
maturin build --release

License

MIT

Links