Skip to content

Black

A Python code formatter that rewrites your files to one consistent style with little configuration.

Stars
42.1k
Forks
3k
Licence
MIT
Language
Python
Last update
4 days ago
Type
Dev tool

What it is

Black is a command-line tool that automatically rewrites Python code into a consistent layout, so you stop spending time on spacing, line breaks, and quote style. It is opinionated and has few settings by design, so teams and projects end up looking alike. People use it to keep code reviews focused on logic rather than formatting.

  • Format a single Python file or an entire directory with one command
  • Format Jupyter Notebooks after installing the jupyter extra
  • Configure include and exclude patterns for a project through pyproject.toml
  • Run Black automatically before each commit using pre-commit

Great for

  • Python developers who want formatting handled automatically
  • Teams that want every project member's code to look the same
  • Projects that already use pre-commit hooks or CI checks
  • People who prefer not to debate style rules

Not ideal for

  • Anyone who wants fine-grained control over formatting choices, since the README says style options are deliberately limited
  • Projects that need to run on Python versions older than 3.10, since the README says Black requires Python 3.10+ to run
Step-by-step guide: how to use BlackInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Python 3.10+

    Install Black with pip

    pip install black
  2. 2

    Run it

    • Install Black with pip install black
    • Run black on a file or folder, for example: black {source_file_or_directory}
    • Review the changes it made, then commit them
  3. 3

    Get the most out of it

    • Add a [tool.black] section to pyproject.toml to set include and exclude patterns for your project
    • Install the jupyter extra with pip install "black[jupyter]" to format notebooks
    • Use the documentation's configuration guide to adjust defaults where needed

Downloads

Strengths

  • The README describes it as producing the smallest diffs possible, which makes code review easier
  • Few configuration options are needed, and the README says the defaults are intended to work for most projects
  • Documented stability policy means large style changes are not expected going forward

Trade-offs

  • Its opinionated style means you cannot tune many formatting details
  • The README notes it reformats files in place, so you should use version control before running it on existing code

How it compares

ProjectStarsTypeLevelUpdatedBest for
black (this)42.1kDev toolbeginner4 days agoPython developers who want formatting handled automatically
prettier52.4kDev toolbeginner4 days agoTeams that want one shared code style without writing their own rules
tools23.3kDev toolintermediate3.2 years agoDevelopers who want one tool for formatting and linting JavaScript or TypeScript
gitingest16.1kDev toolbeginner4 days agoDevelopers who want to give an AI assistant context about a codebase
CodeEdit23.1kAppbeginner19 days agoDevelopers on a Mac who work on non-Apple projects and want a native macOS editor
gitdiagram18.7kAppintermediate7 days agoDevelopers getting oriented in an unfamiliar codebase

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.