The uncompromising Python code formatter https://black.readthedocs.io/en/stable/
Find a file
dependabot[bot] 8889e20a76
Some checks failed
diff-shades / configure (push) Has been cancelled
docker / build (linux/amd64) (push) Has been cancelled
docker / build (linux/arm64) (push) Has been cancelled
docs / docs (ubuntu-latest) (push) Has been cancelled
docs / docs (windows-latest) (push) Has been cancelled
fuzz / fuzz (3.10) (push) Has been cancelled
fuzz / fuzz (3.11) (push) Has been cancelled
fuzz / fuzz (3.12) (push) Has been cancelled
fuzz / fuzz (3.13) (push) Has been cancelled
fuzz / fuzz (3.14) (push) Has been cancelled
lint and format / lint (push) Has been cancelled
build and publish / generate wheels matrix (push) Has been cancelled
build and publish / sdist + pure wheel (push) Has been cancelled
test release tool / test-release-tool (macOS-latest, 3.12) (push) Has been cancelled
test release tool / test-release-tool (macOS-latest, 3.13) (push) Has been cancelled
test release tool / test-release-tool (macOS-latest, 3.14) (push) Has been cancelled
test release tool / test-release-tool (ubuntu-latest, 3.12) (push) Has been cancelled
test release tool / test-release-tool (ubuntu-latest, 3.13) (push) Has been cancelled
test release tool / test-release-tool (ubuntu-latest, 3.14) (push) Has been cancelled
test release tool / test-release-tool (windows-latest, 3.12) (push) Has been cancelled
test release tool / test-release-tool (windows-latest, 3.13) (push) Has been cancelled
test release tool / test-release-tool (windows-latest, 3.14) (push) Has been cancelled
test / test (macOS-latest, 3.10) (push) Has been cancelled
test / test (macOS-latest, 3.11) (push) Has been cancelled
test / test (macOS-latest, 3.12.10) (push) Has been cancelled
test / test (macOS-latest, 3.13) (push) Has been cancelled
test / test (macOS-latest, 3.14) (push) Has been cancelled
test / test (macOS-latest, pypy-3.11) (push) Has been cancelled
test / test (ubuntu-latest, 3.10) (push) Has been cancelled
test / test (ubuntu-latest, 3.11) (push) Has been cancelled
test / test (ubuntu-latest, 3.12.10) (push) Has been cancelled
test / test (ubuntu-latest, 3.13) (push) Has been cancelled
test / test (ubuntu-latest, 3.14) (push) Has been cancelled
test / test (ubuntu-latest, pypy-3.11) (push) Has been cancelled
test / test (windows-11-arm, 3.11) (push) Has been cancelled
test / test (windows-11-arm, 3.12.10) (push) Has been cancelled
test / test (windows-11-arm, 3.13) (push) Has been cancelled
test / test (windows-11-arm, 3.14) (push) Has been cancelled
test / test (windows-latest, 3.10) (push) Has been cancelled
test / test (windows-latest, 3.11) (push) Has been cancelled
test / test (windows-latest, 3.12.10) (push) Has been cancelled
test / test (windows-latest, 3.13) (push) Has been cancelled
test / test (windows-latest, 3.14) (push) Has been cancelled
test / test (windows-latest, pypy-3.11) (push) Has been cancelled
test / uvloop (macOS-latest) (push) Has been cancelled
test / uvloop (ubuntu-latest) (push) Has been cancelled
zizmor / zizmor (push) Has been cancelled
diff-shades / analysis / base / (push) Has been cancelled
diff-shades / analysis / target / (push) Has been cancelled
diff-shades / compare / (push) Has been cancelled
docker / push (push) Has been cancelled
build and publish / mypyc wheels (push) Has been cancelled
build and publish / publish-mypyc (push) Has been cancelled
build and publish / publish-hatch (push) Has been cancelled
build and publish / update stable branch (push) Has been cancelled
test / coveralls-finish (push) Has been cancelled
Bump actions/setup-python from 6.1.0 to 6.2.0 (#4977)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2026-01-31 10:09:44 -06:00
.github Bump actions/setup-python from 6.1.0 to 6.2.0 (#4977) 2026-01-31 10:09:44 -06:00
action feat: add output-file input for clean Black logging (#4824) 2025-11-21 16:38:53 -06:00
autoload Various CI and doc refactors (#4928) 2026-01-15 22:05:06 -06:00
docs Simplify power operator hugging implementation (#4918) 2026-01-22 18:35:19 -06:00
gallery Various CI and doc refactors (#4928) 2026-01-15 22:05:06 -06:00
plugin Various CI and doc refactors (#4928) 2026-01-15 22:05:06 -06:00
profiling Move profiling data out of tests/data 2018-06-09 15:48:41 -07:00
scripts Prepare 2026.1.0 release (#4892) 2026-01-17 22:30:36 -06:00
src Don't double-decode input, causing non-UTF-8 files to be corrupted (#4964) 2026-01-23 10:05:02 -06:00
tests Don't double-decode input, causing non-UTF-8 files to be corrupted (#4964) 2026-01-23 10:05:02 -06:00
.flake8 Remove old noqa comments and disable C901 globally (#4874) 2025-11-28 08:03:43 -06:00
.git_archival.txt 📦 Tell git archive to include numbered tags (#4593) 2025-02-28 16:09:40 -08:00
.gitattributes Add *.py diff=python to .gitattributes (#4531) 2024-12-11 11:35:20 -08:00
.gitignore chore: gitignore .pyd files (#4798) 2025-10-19 16:47:48 -05:00
.pre-commit-config.yaml [pre-commit.ci] pre-commit autoupdate (#4974) 2026-01-27 10:13:18 -06:00
.pre-commit-hooks.yaml Revert "confine pre-commit to stages (#3940)" (#4137) 2024-01-01 16:55:25 -08:00
.prettierrc.yaml Various CI and doc refactors (#4928) 2026-01-15 22:05:06 -06:00
.readthedocs.yaml Various CI and doc refactors (#4928) 2026-01-15 22:05:06 -06:00
action.yml Lingering CI/CD pins, add cooldowns, remove template injections (#4906) 2025-12-11 12:10:20 -08:00
AUTHORS.md Various CI and doc refactors (#4928) 2026-01-15 22:05:06 -06:00
CHANGES.md Don't double-decode input, causing non-UTF-8 files to be corrupted (#4964) 2026-01-23 10:05:02 -06:00
CITATION.cff Fix typo in CITATION.cff (#3779) 2023-07-10 19:38:01 -07:00
CONTRIBUTING.md Small improvements to the contributing basics (#4502) 2024-11-05 08:03:32 -08:00
Dockerfile Various CI and doc refactors (#4928) 2026-01-15 22:05:06 -06:00
LICENSE Initial commit 2018-03-14 12:55:32 -07:00
pyproject.toml [pre-commit.ci] pre-commit autoupdate (#4943) 2026-01-19 21:10:32 -06:00
README.md Drop support for EOL Python 3.9 (#4842) 2025-11-16 21:16:43 -06:00
SECURITY.md Add SECURITY.md (#3612) 2023-03-18 10:41:48 -07:00
tox.ini Various CI and doc refactors (#4928) 2026-01-15 22:05:06 -06:00

Black Logo

The Uncompromising Code Formatter

Actions Status Documentation Status Coverage Status License: MIT PyPI Supported Python Versions Downloads conda-forge Code style: black

“Any color you like.”

Black is the uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting. In return, Black gives you speed, determinism, and freedom from pycodestyle nagging about formatting. You will save time and mental energy for more important matters.

Blackened code looks the same regardless of the project you're reading. Formatting becomes transparent after a while and you can focus on the content instead.

Black makes code review faster by producing the smallest diffs possible.

Try it out now using the Black Playground. Watch the PyCon 2019 talk to learn more.


Read the documentation on ReadTheDocs!


Installation and usage

Installation

Black can be installed by running pip install black. It requires Python 3.10+ to run. If you want to format Jupyter Notebooks, install with pip install "black[jupyter]".

Usage

To get started right away with sensible defaults:

black {source_file_or_directory}

You can run Black as a package if running it as a script doesn't work:

python -m black {source_file_or_directory}

Further information can be found in our docs:

Black is already successfully used by many projects, small and big. Black has a comprehensive test suite, with efficient parallel tests, and our own auto formatting and parallel Continuous Integration runner. Now that we have become stable, you should not expect large formatting changes in the future. Stylistic changes will mostly be responses to bug reports and support for new Python syntax. For more information please refer to The Black Code Style.

Also, as a safety measure which slows down processing, Black will check that the reformatted code still produces a valid AST that is effectively equivalent to the original (see the Pragmatism section for details). If you're feeling confident, use --fast.

The Black code style

Black is a PEP 8 compliant opinionated formatter. Black reformats entire files in place. Style configuration options are deliberately limited and rarely added. It doesn't take previous formatting into account (see Pragmatism for exceptions).

Our documentation covers the current Black code style, but planned changes to it are also documented. They're both worth taking a look at:

Changes to the Black code style are bound by the Stability Policy:

Please refer to this document before submitting an issue. What seems like a bug might be intended behaviour.

Pragmatism

Early versions of Black used to be absolutist in some respects. They took after its initial author. This was fine at the time as it made the implementation simpler and there were not many users anyway. Not many edge cases were reported. As a mature tool, Black does make some exceptions to rules it otherwise holds.

Please refer to this document before submitting an issue just like with the document above. What seems like a bug might be intended behaviour.

Configuration

Black is able to read project-specific default values for its command line options from a pyproject.toml file. This is especially useful for specifying custom --include and --exclude/--force-exclude/--extend-exclude patterns for your project.

You can find more details in our documentation:

And if you're looking for more general configuration documentation:

Pro-tip: If you're asking yourself "Do I need to configure anything?" the answer is "No". Black is all about sensible defaults. Applying those defaults will have your code in compliance with many other Black formatted projects.

Used by

The following notable open-source projects trust Black with enforcing a consistent code style: pytest, tox, Pyramid, Django, Django Channels, Hypothesis, attrs, SQLAlchemy, Poetry, PyPA applications (Warehouse, Bandersnatch, Pipenv, virtualenv), pandas, Pillow, Twisted, LocalStack, every Datadog Agent Integration, Home Assistant, Zulip, Kedro, OpenOA, FLORIS, ORBIT, WOMBAT, and many more.

The following organizations use Black: Dropbox, KeepTruckin, Lyft, Mozilla, Quora, Duolingo, QuantumBlack, Tesla, Archer Aviation.

Are we missing anyone? Let us know.

Testimonials

Mike Bayer, author of SQLAlchemy:

I can't think of any single tool in my entire programming career that has given me a bigger productivity increase by its introduction. I can now do refactorings in about 1% of the keystrokes that it would have taken me previously when we had no way for code to format itself.

Dusty Phillips, writer:

Black is opinionated so you don't have to be.

Hynek Schlawack, creator of attrs, core developer of Twisted and CPython:

An auto-formatter that doesn't suck is all I want for Xmas!

Carl Meyer, Django core developer:

At least the name is good.

Kenneth Reitz, creator of requests and pipenv:

This vastly improves the formatting of our code. Thanks a ton!

Show your style

Use the badge in your project's README.md:

[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

Using the badge in README.rst:

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black

Looks like this: Code style: black

License

MIT

Contributing

Welcome! Happy to see you willing to make the project better. You can get started by reading this:

You can also take a look at the rest of the contributing docs or talk with the developers:

Change log

The log has become rather long. It moved to its own file.

See CHANGES.

Authors

The author list is quite long nowadays, so it lives in its own file.

See AUTHORS.md

Code of Conduct

Everyone participating in the Black project, and in particular in the issue tracker, pull requests, and social media activity, is expected to treat other people with respect and more generally to follow the guidelines articulated in the Python Community Code of Conduct.

At the same time, humor is encouraged. In fact, basic familiarity with Monty Python's Flying Circus is expected. We are not savages.

And if you really need to slap somebody, do it with a fish while dancing.