In uv version 0.8.13, released one or two days ago, uv added the command format
that allows you to format your Python code directly through the uv CLI.
First and foremost, make sure you're rocking uv 0.8.13 or greater by running uv self update
.
To format your code with uv you can simply run uv format
, which will use Ruff to format the code in your current directory:
$ uv format
The idea is not to have uv replace Ruff; it's just so that you don't have to think about a separate tool if you don't want to.
uv format
argumentsuv format
accepts the same arguments and options that ruff format
accepts, so you'll want to check the Ruff docs to learn more.
My favourite option is --diff
, to take a look at the formatting diff without doing any formatting changes.
As of now, the feature is marked as being experimental, which means it might change in the future!
Get a daily drop of Python knowledge. A short, effective tip to start writing better Python code: more idiomatic, more effective, more efficient, with fewer bugs. Subscribe here.