Listen to this story
|
Ruff, a Python linter written in Rust, has taken the Python community by storm with its blazing fast performance and comprehensive feature set.
The project, created by Charlie Marsh in 2022, recently hit a major milestone with over 400 contributors on GitHub. Marsh also said on X, “Just got confirmation that an >8M LoC codebase successfully migrated to ruff format” Compared to the linters like Flake8, Pylint or Black, Ruff is extremely fast and accurate and is quickly adopted by the community.
Linters are essential tools for any programming language, helping developers catch potential errors, enforce coding standards, and maintain a consistent style across large codebases. In the Python ecosystem, popular linters like Flake8, Pylint, and Black have been widely used for years. However, these tools often come with performance trade-offs, especially when dealing with large projects.
Ruff, on the other hand, is surprisingly quick compared to the others while also integrating more functionality into a single, unified interface. By leveraging the speed and safety of Rust, Ruff is able to analyse and format code at an astonishing pace.
In benchmarks, Ruff has proven to be 10-100x faster than tools like Flake8 and Black, making it a game-changer for developers working on large codebases.
Debugging at Lightning Speed
One of the key factors contributing to Ruff’s speed is its built-in caching mechanism, which avoids re-analysing unchanged files. This, combined with its highly optimised Rust implementation, allows Ruff to blaze through even the most massive codebases in a matter of seconds. Rust is already known for its speed and memory efficiency, making it an ideal choice for performance-critical applications like linters.
As Nick Schrock, founder of Elementl and co-creator of GraphQL, noted, “On our largest module pylint takes about 2.5 minutes, parallelised across 4 cores on my M1. Running ruff against our entire codebase takes .4 seconds.”
Ruff’s speed is not its only selling point, however. The tool boasts an impressive array of features, including over 700 built-in rules, native re-implementations of popular Flake8 plugins, and drop-in parity with tools like isort and Black. This means that developers can replace multiple linters and formatters with Ruff, simplifying their development workflows and reducing the overall complexity of their toolchains.
The Python community has been quick to embrace Ruff, with many high-profile projects like Apache Airflow, FastAPI, Hugging Face, Pandas, and SciPy already adopting it. Users have expressed disbelief at how quickly it can analyse their code. Sebastián Ramírez, creator of FastAPI, quipped, “Ruff is so fast that sometimes I add an intentional bug in the code just to confirm it’s actually running and checking the code.”
Perhaps the most surprising endorsement of Ruff comes from the Pylint project itself. In a recent development, even the Pylint, codebase has begun using Ruff for linting, a testament to the tool’s growing popularity and effectiveness.
The Inception
Charlie Marsh was motivated to build Ruff to solve his own issues with coding, “it’s the tooling I wish I’d had,” he said in an interview. Marsh’s ultimate goal is to create an integrated toolchain that includes not only a linter but also an auto formatter and potentially a type checker. By bundling these functionalities together, Ruff would provide a more powerful and efficient solution for Python developers.
Despite the challenges of building a new tool and learning Rust, Marsh stayed committed and even announced his new company, Astral, which will continue developing Ruff and other high-performance Python tools.
“To me, the community’s response to Ruff is itself evidence of an opportunity to make the Python ecosystem more productive by building great tools. Astral exists to meet that opportunity.”
Marsh said his ultimate goal is an integrated toolchain that includes not just a linter, but also an auto formatter and possibly a type checker. By combining these tools, Ruff aims to provide an even more powerful and efficient solution for Python developers.
As Ruff continues to evolve and grow, it is set to change how Python developers work. With its speed, features, and community support, Ruff is on track to become the standard for Python linting and formatting.