black (psf/black)

Searching Database…

42.2K ·GitHub
What is this?Black is the uncompromising Python code formatter: it reformats your code into one opinionated style, freeing you from hand-formatting and style debates.
What makes it 'uncompromising' compared to other formatters?It is a PEP 8 compliant formatter with deliberately limited style options. It rewrites entire files in place, ignoring previous formatting, so Blackened code looks the same across all projects.
How do I install and run it?Run pip install black, then point it at your files or project. Sensible defaults work out of the box with no configuration needed.
Do I need Python installed, or can I just grab a binary?Black normally runs on Python 3.10 or newer, but you can skip installing Python entirely by downloading a PyInstaller-built standalone executable from the latest GitHub release.
Can reformatting ever break my code?By default Black only accepts safe changes: it verifies that the reformatted code still produces a valid AST effectively equivalent to the original. A --fast flag skips that check if you are feeling confident.
Does it matter which operating system I'm on?Not really. Black is a pip-installable Python package, so it runs anywhere Python runs: Windows, macOS and Linux.
Do I have to configure the style before using it on my project?No. Black is all about sensible defaults and its style options are deliberately limited. Project-specific defaults for command-line options like --include or --exclude can be set in a pyproject.toml file.
Can it format Jupyter Notebooks too?Yes. Install with pip install 'black[jupyter]' and Black will handle notebooks as well.
Who relies on Black in production?Notable open-source projects include pytest, Django, pandas, Pillow, Poetry, Home Assistant and Zulip, plus organizations like Dropbox, Mozilla, Lyft and Tesla.
Will the Black code style change under me over time?No big rewrites are expected. Black is stable, so future stylistic changes will mostly respond to bug reports and new Python syntax, following a published stability policy.
What are similar projects?ruff, yapf, rubocop, PHP-CS-Fixer, SwiftLint, english-rs, rector, cli
Creator
psf
Size
8.6 MB
Stars
42.2K
Age
8y
Commits · 90 Days