The Ruff Formatter – Python’s Fastest Formatter!

The Ruff project was released about a year ago and stormed the Python world. Ruff is written in Rust, but lints Python superfast.

This week, the Ruff formatter 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!

Introducing Ruff

Ruff was released in the past year and has been gaining a lot of popularity. Ruff’s claim to fame is that it is fast because it was written in Rust! Ruff is 10-100x faster than existing linters!

Ruff has near-parity with the built-in Flake8 rule set and 500+ rules that reimplement many of Flake8’s popular plugins.

Installing Ruff

You can install Ruff using pip:

pip install ruff

If you are on Mac or Linux and you use Brew, you can use that too:

brew install ruff

Ruff is also installable with conda:

conda install -c conda-forge ruff

Or if you have an existing project based on Poetry:

poetry add ruff

Using Ruff

Now that you have Ruff installed, let’s look at a few examples of running Ruff on your code base!

Here are some examples from the Ruff docs:

# Lint all files in the current directory (and any subdirectories)
ruff check .         

# Lint all files in `/path/to/code` (and any subdirectories)
ruff check path/to/code/    

# Lint all `.py` files in `/path/to/code`
ruff check path/to/code/*.py        

# Lint ``
ruff check path/to/code/to/  

Ruff also supports a handy mode to watch for changes on a folder and re-run when a change is detected.

Here is the command you can use for that:

ruff check path/to/code/ --watch

Wrapping Up

Ruff combines functionality from flake8, pyLint, Black, isort into one neat library. Try out the Ruff formatter today! We believe you’ll like it, and it will shorten your development and build times too!

Matt von Rohr
Matt von Rohr

#ai #datascience #machinelearning #dataengineering #dataintegration

Articles: 27

Leave a Reply

Your email address will not be published. Required fields are marked *