For a good few years, Black has been the defacto Python formatter. With the recent release of a new tool called Ruff, which describes itself as:

An extremely fast Python linter and code formatter ...

This raises the question:

What is the difference between Black and Ruff?

First of all, for those new to Python formatting and asking: What is a Python Formatter?

A formatter is a tool that automates the process of formatting your code to a set of common styling standards. Saving time for the developer, whilst also aligning teams to a common coding style.

Black vs Ruff

To best answer this, let's first look at each of the tool features:

Black

  • Written in Python.
  • A formatter for Python code.

Ruff

  • Written in Rust (fast!)
  • Provides formatting features for a drop-in replacement for Black.
  • Provides linting features for a drop-in replacement for flake8 (and its various plugins), isort, bandit.

Therefore, the clear destination between the two tools is Ruff's speed and also Ruff's functionality to replace the various linting and formatting tools used within a Python project.

Which Should You Choose?

The choice between Black and Ruff really depends on the needs of your project and your workflow requirements.

If speed is a priority, or if you're aiming to streamline your project infrastructure and Continuous Integration (CI) processes by consolidating various tools, then Ruff is a great choice. On the other hand, if your project is already tailored to Black, or if you prefer a separate tool for code formatting, sticking with Black might be the way to go.

Ready to Master Network Automation? Start Your Journey Today!
Our membership provides:
  • Full deep-dive course library (inc. Batfish, pyATS, Netmiko)
  • Code repositories inc. full course code, scripts and examples
  • 24x7 multi-vendor labs (Arista, Cisco, Juniper)
  • Private online community
  • Live monthly tech sessions
  • Access to tech session library

Join Now ➜