explaingit

psf/black

📈 Trending41,512PythonAudience · developerComplexity · 2/5ActiveLicenseSetup · easy

TLDR

Black is an opinionated Python code formatter that automatically rewrites code to a single consistent style, eliminating formatting debates on development teams.

Mindmap

mindmap
  root((Black))
    What it does
      Auto-formats Python
      Enforces one style
      Parses to AST
      Regenerates code
    Why use it
      Stops style debates
      Deterministic output
      Reduces diff noise
      Safety verified
    How to use
      Run on files
      Pre-commit hooks
      CI integration
    Tech stack
      Python 3.10+
      pip install
      AST parsing

Things people build with this

USE CASE 1

Automatically format all Python files in a project to enforce consistent style without manual configuration.

USE CASE 2

Integrate into a pre-commit hook so code is formatted before developers commit changes.

USE CASE 3

Add to a CI pipeline to ensure all merged code follows the same formatting standard.

USE CASE 4

Eliminate code review discussions about quote styles, line breaks, and indentation by letting Black decide.

Tech stack

PythonAST

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose, including commercial use, as long as you keep the copyright notice and license text.

In plain English

Black is the "uncompromising" Python code formatter, a tool that automatically rewrites Python source files to conform to a single, consistent style. The word "uncompromising" is the key to understanding its design philosophy: unlike older linters or formatters that offer dozens of configuration options for line length, quote style, bracket placement, and so on, Black has very few settings. It makes all the decisions for you. The problem Black solves is the endless, low-stakes debate that happens on development teams about code style. Should strings use single quotes or double quotes? Where should long function calls be split across lines? How many blank lines between methods? These questions consume surprising amounts of attention during code review without actually improving the software. Black's answer is: stop arguing, just run the formatter. Here is how it works: you run black myfile.py or point it at a directory, and Black reformats the files in place using its opinionated rules. It parses the Python source into an abstract syntax tree (a structural representation of the code), then regenerates the code from scratch in Black's canonical style, normalizing indentation, line lengths, quote style, trailing commas, and more. As a safety check, Black verifies that the reformatted code produces an equivalent AST to the original, so it cannot accidentally change what the code does. Because Black's output is deterministic, the same input always produces the same output, it eliminates formatting-related noise in diffs and code reviews. Two developers can independently edit the same file, run Black, and get identical results. You would use Black as part of any Python project's development setup, typically integrated with a pre-commit hook or CI pipeline so that all code is automatically formatted before it is committed. The stack is Python 3.10 or later, installable via pip.

Copy-paste prompts

Prompt 1
How do I set up Black to automatically format my Python project before every commit?
Prompt 2
Show me how to configure Black in my GitHub Actions workflow to check formatting on pull requests.
Prompt 3
What are the main formatting rules Black enforces, and why does it have so few configuration options?
Prompt 4
How can I use Black's AST verification to ensure my code's behavior doesn't change after formatting?
Prompt 5
I want to integrate Black into my team's development process, what's the recommended setup?
Open on GitHub → Explain another repo

Generated 2026-05-18 · Model: sonnet-4-6 · Verify against the repo before relying on details.