The uncompromising code formatter¶

By using Black, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

Black makes code review faster by producing the smallest diffs possible. Blackened code looks the same regardless of the project you’re reading. Formatting becomes transparent after a while and you can focus on the content instead.

Try it out now using the Black Playground.

Note

Black is beta.

Testimonials¶

Dusty Phillips, writer:

Black is opinionated so you don’t have to be.

Hynek Schlawack, creator of attrs, core developer of Twisted and CPython:

An auto-formatter that doesn’t suck is all I want for Xmas!

Carl Meyer, Django core developer:

At least the name is good.

Kenneth Reitz, creator of requests and pipenv:

This vastly improves the formatting of our code. Thanks a ton!

Contents¶

  • Installation and usage
    • Installation
    • Usage
    • Command line options
    • NOTE: This is a beta product
  • The Black code style
    • How Black wraps lines
    • Line length
    • Empty lines
    • Trailing commas
    • Strings
    • Numeric literals
    • Line breaks & binary operators
    • Slices
    • Parentheses
    • Call chains
    • Typing stub files
  • pyproject.toml
    • What on Earth is a pyproject.toml file?
    • Where Black looks for the file
    • Configuration format
    • Lookup hierarchy
  • Editor integration
    • Emacs
    • PyCharm/IntelliJ IDEA
    • Vim
    • Visual Studio Code
    • SublimeText 3
    • Jupyter Notebook Magic
    • Python Language Server
    • Atom/Nuclide
    • Other editors
  • blackd
    • Usage
    • Protocol
  • Version control integration
  • Ignoring unmodified files
  • Contributing to Black
    • Bird’s eye view
    • Technicalities
    • Hygiene
    • Finally
  • Show your style
  • Change Log
    • 19.3 b0
    • 18.9 b0
    • 18.6 b4
    • 18.6 b3
    • 18.6 b2
    • 18.6 b1
    • 18.6 b0
    • 18.5 b1
    • 18.5 b0
    • 18.4 a4
    • 18.4 a3
    • 18.4 a2
    • 18.4 a1
    • 18.4 a nought.
    • 18.3 a4
    • 18.3 a3
    • 18.3 a2
    • 18.3 a1
    • 18.3 a nought.
  • Developer reference
    • Black classes
    • Enums
    • Black functions
    • Black exceptions
  • Authors