LinuxCommandLibrary

black

Opinionated Python code formatter

TLDR

Format Python file

$ black [script.py]
copy
Format entire project
$ black [src/]
copy
Check without modifying
$ black --check [script.py]
copy
Diff instead of rewriting
$ black --diff [script.py]
copy
Set line length
$ black -l [100] [script.py]
copy

SYNOPSIS

black [options] files

DESCRIPTION

black is an opinionated Python code formatter. It enforces a consistent style by reformatting code automatically with minimal configuration. Black's approach is to eliminate debate about formatting by providing one correct way.
The tool integrates with editors and CI pipelines to ensure consistent Python code style.

PARAMETERS

--check

Check if files would be reformatted (exit 1 if yes)
--diff
Show diff instead of rewriting
-l, --line-length n
Line length (default: 88)
--target-version py
Python version (py37, py38, py39, etc.)
--exclude pattern
Files/directories to exclude
--include pattern
Files/directories to include
--quiet
Minimal output
--verbose
Verbose output
--color/--no-color
Colored output

CONFIGURATION

pyproject.toml

Project-level configuration under `[tool.black]` section. Supports `line-length`, `target-version`, `include`, and `exclude` settings.

FEATURES

- Deterministic formatting
- Minimal configuration
- Fast (multi-core processing)
- Editor integration
- Git integration
- Safe (preserves AST)
- PEP 8 compliant
- ipynb support

WORKFLOW

$ # Format file
black script.py

# Format directory
black src/

# Check in CI
black --check .

# Show what would change
black --diff script.py

# Specific Python version
black --target-version py39 script.py
copy

CAVEATS

Opinionated (limited configuration). May conflict with other formatters. 88 character default line length differs from PEP 8's 79. Some formatting choices controversial. Requires Python 3.6+.

HISTORY

Black was created by Ɓukasz Langa in 2018 to provide deterministic Python formatting, eliminating formatting debates and reducing diff noise.

SEE ALSO

autopep8(1), isort(1), flake8(1)

> TERMINAL_GEAR

Curated for the Linux community

Bmax Mini PC B2 Power Intel 5205U 8GB DDR4 256GB M.2 NVMe SSD ,HDMI 1.4&DP 1.2, USB3.2,4K Dual Display 2.4G/5G WiFi & BT5.0 Mini Desktop Computers /Office/Design

Bmax Mini PC B2 Power Intel 5205U 8GB DDR4 256GB M.2 NVMe SSD ,HDMI 1.4&DP 1.2, USB3.2,4K Dual Display 2.4G/5G WiFi & BT5.0 Mini Desktop Computers /Office/Design

$169.99
Raspberry Pi 5 8GB

Raspberry Pi 5 8GB

$134.50
KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

KIWITATA 2X Classic SNES USB Controller for PC Gamings, Retro SNES Wired USB Game Emulator Controller for Windows XP 7 8 11 Mac Raspberry Pi

$16.99
Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community

nuphy Air75 V2 Portable 75% Mechanical Keyboard,Wireless Keyboard

nuphy Air75 V2 Portable 75% Mechanical Keyboard,Wireless Keyboard

$129.95
Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

Lenovo Gen 13 ThinkPad X1 Carbon Touchscreen Laptop with Intel Ultra 7 265U Processor, 14" WUXGA 100% sRGB, 32GB DDR5 RAM, 1TB NVMe Performance SSD, FHD+ IR+ RGB Camera, and Windows 11 Pro

$1,589.00
GMKtec Gaming PC, K11 AMD Ryzen 9 8945HS, 32GB DDR5 RAM 1TB Mini PC Desktop Computer, Oculink, Dual NIC 2.5GbE LAN, HDMI/DisplayPort/USB4*2

GMKtec Gaming PC, K11 AMD Ryzen 9 8945HS, 32GB DDR5 RAM 1TB Mini PC Desktop Computer, Oculink, Dual NIC 2.5GbE LAN, HDMI/DisplayPort/USB4*2

$739.99