Black – opinionated Python code formatter

Black is an opinionated Python code formatter designed to produce consistent source code with minimal configuration. It automatically reformats code according to a standardised style, reducing the need for developers to make individual decisions about spacing, indentation and line wrapping.

Unlike highly configurable formatters, Black deliberately offers relatively few stylistic options. This approach is intended to eliminate formatting disagreements and make code easier to read across different projects.

Black is particularly useful in collaborative development, where consistent formatting helps reviewers concentrate on substantive code changes rather than differences in presentation. It can be incorporated into existing development workflows and used to enforce formatting standards automatically.

This is free and open source software.

Key Features

  • Automatically formats Python source code according to a consistent, opinionated style.
  • Produces PEP 8-compliant formatting with sensible defaults.
  • Normalises whitespace, indentation, line breaks and expression layout.
  • Produces stable output designed to minimise unnecessary code differences.
  • Checks that formatting preserves the effective abstract syntax tree.
  • Supports configurable line length and target Python syntax.
  • Offers options to preserve existing string quotes and control trailing comma behaviour.
  • Provides check and diff modes for inspecting formatting without modifying files.
  • Supports formatting selected line ranges within individual Python files.
  • Can format Python source files, typing stub files and Jupyter notebooks.
  • Supports project configuration through pyproject.toml.
  • Allows files and directories to be included or excluded through configurable patterns.
  • Provides formatting exclusion comments for selected code regions.
  • Includes blackd, an HTTP server for integration with editors and other development tools.
  • Integrates with pre-commit, continuous integration services and code editors.
  • Cross-platform support – runs on Linux, macOS, and Windows.

Website: github.com/psf/black
Support:
Developer: Łukasz Langa
License: MIT License

Black is written in Python. Learn Python with our recommended free books and free tutorials.


Related Software

Python Code Formatters
RuffExtremely fast Python linter and code formatter
YAPFPython formatter based on clang-format
BlackUncompromising Python code formatter
isortPython utility and library to sort imports
autopep8Formats Python code to conform to the PEP 8 style guide
DarkerApply black reformatting to Python files
PyinkPython code formatter
blueSomewhat less uncompromising code formatter than black
μsortSorts import statements
eradicateRemove commented-out code from Python files

Read our verdict in the software roundup.


Best Free and Open Source Software LinuxLinks helps you discover the best free and open source software for Linux. Explore our extensive collection of recommended applications, including alternatives to popular proprietary software.

We also publish software reviews, Linux tutorials, hardware reviews, free programming books and articles covering the wider open source community. Browse our Linux resources to discover more.

Know a useful free and open source Linux application we haven't covered? Suggest a program for inclusion.

Has your software been featured on LinuxLinks? Display one of our Featured on LinuxLinks badges on your website or GitHub README.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted