2021-11-29

Black - The Code Formatter

black logo Black is a non-configurable code formatter.

Install Black for Jupyter notebook

jupyter nbextension install https://github.com/drillan/jupyter-black/archive/master.zip --user
jupyter nbextension enable jupyter-black-master/jupyter-black

Change the line length character limit in Black

To change the character limit for the Black Python formatter, you can add the following section to pyproject.toml file:

[tool.black]
line-length = 119

For info on how to configure black with vscode? See [[change_black_line_length|here]].

Usages of black

  • with tox
  • in pre-commit hooks
  • as an external tool in PyCharm

Similar tools

  • [[yapf]]
  • google/pyink a Python formatter, forked from Black with a few different formatting behaviors.

up::[[MOC_Python]] X::[[black_keep_single_strings]] X::[[black_change_max_line_length]] X::[[black_formatter_avoid_destroying_git_blame]] X::[[black_yapf]] X::[[black_configuration_files]]