Black

Black formats your code in a nice and deterministic format.

See also

What characterises readable code is well described in Trey Hunner’s blog post Craft Your Python Like Poetry.

Installation

$ uv add black

Check

Then you can check the installation with

$ uv run black /PATH/TO/YOUR/SOURCE/FILE

Integration

With jupyter-black you can already use Black in your Jupyter notebooks.

See also

Integration into other editors such as PyCharm, Wing IDE or Vim is also possible, see Editor integration

Configuration

In contrast to Black’s standard 88-character formatting, however, I prefer a line length of 79 characters.

For this you can enter the following in pyproject.toml:

[tool.black]
line-length = 79

See also

You can get more information about the configuration of Black in the Toml file in pyproject.toml.