talira

The uncompromising Python code formatter: one deterministic style, no configuration debates

open sourceMITfree

A Python code formatter that reformats whole files to one consistent style, so formatting stops being a matter of taste or a subject of code review and diffs stay small. It checks that the reformatted code produces an equivalent AST unless run with --fast. Besides the command line, it runs as a server (blackd), in a Docker image, in editors, in GitHub Actions and pre-commit hooks, and on Jupyter Notebooks. Black is stable, so formatting changes between releases are limited to bug fixes and new Python syntax. It's a Python Software Foundation project, MIT licensed.

Problems it solves

  • stop arguing about Python code style in code review
  • format all of my Python code the same way automatically
  • keep formatting diffs small across a team's Python project

Features

  • deterministic formatting of whole Python files
  • checks the reformatted code is equivalent (AST check)
  • blackd formatting server and Docker image
  • editor, GitHub Actions and version control integrations
  • formats Jupyter Notebooks

Alternatives

The same job

These do what Black does.

  1. YAPF Configurable Python code formatter based on clang-format's algorithm
  2. Ruff An extremely fast Python linter and code formatter, written in Rust
  3. autopep8 Automatically reformats Python code to follow the PEP 8 style guide

Compare Black with the top 3