The Ruff project was released about a year ago and stormed the Python world. Ruff is written in Rust, but lints Python super fast. You can read all about it in An Intro to Ruff.
This week, the Ruff formatted was released! You can still use Ruff to lint your Python code, but now you can also use Ruff to format your code with 99.9% Black compatibility. The good news? It’s over 30x faster than Black!
If you haven’t got Ruff already, you’ll need to install it.
pip install ruff
If you do already have Ruff, be sure to upgrade to latest so you can give the formatted version a try!
Formatting with Ruff
To format your code with Ruff, you need to run ruff format.
Here’s an example of formatting your current folder:
ruff format .
The official announcement for the Ruff formatter shows it formatting Django, Zulip and other Python projects in less than a second.
Ruff is Configurable
The Ruff formatter adds some configuration options that are absent from Black. Namely, you can tweak your preferred quote and indentation style:
[tool.ruff.format] quote-style = "single" indent-style = "tab"
Ruff can now replace flake8, pyLint, Black, isort and more. Try out the Ruff formatter today! You’ll like it and it will speed up your development time too!