Black is the uncompromising Python code formatter, designed to automatically format Python code according to a strict, opinionated style. It enforces PEP 8 compliance and eliminates manual formatting decisions, saving time and ensuring consistency across projects.

  • Installation: Install Black using pip install black. For Jupyter Notebooks, use pip install "black[jupyter]".

  • Usage: Format a file or directory with black {source_file_or_directory}. Run as a package with python -m black {source_file_or_directory}.

  • Key Features:

    • No configuration needed: Black uses sensible defaults and requires minimal setup.

    • Deterministic formatting: Code looks the same across all projects.

    • Smaller diffs: Improves code reviews by minimizing formatting changes.

    • Safety checks: Verifies that reformatted code produces the same AST as the original (use --fast to skip checks if confident).

  • Online Playground: Try Black online at https://black.vercel.app/.

  • IDE Integration:

    • VS Code: Install the Python extension and set python.formatting.provider to black and editor.formatOnSave to true.

    • PyCharm: Use the "External Tools" feature to run Black on save.

    • GitHub Actions: Use the run-black-formatter action from GitHub Marketplace.

  • Configuration: Customize behavior via pyproject.toml (e.g., line-length = 79).

  • Adopted by: Major projects like Django, pytest, SQLAlchemy, pandas, and organizations including Dropbox, Mozilla, and Tesla.

Black is stable and rarely changes its style—future updates focus only on bug fixes and new Python syntax support.

🌐
GitHub
github.com › marketplace › actions › run-black-formatter
Run black formatter - GitHub Marketplace
This action runs the black formatter to check/format your python code on a push or pull request. It is similar to reviewdog/action-black that can annotate the black changes required with Reviewdog.
🌐
GitHub
github.com › psf › black
GitHub - psf/black: The uncompromising Python code formatter · GitHub
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.
Starred by 41.4K users
Forked by 2.7K users
Languages   Python
Discussions

Black, the uncompromising Python code formatter, is stable
Change log: https://black.readthedocs.io/en/latest/change_log.html · Going forward we'll follow our stability policy (https://black.readthedocs.io/en/latest/the_black_code_style/...) More on news.ycombinator.com
🌐 news.ycombinator.com
288
500
January 1, 2022
My unpopular opinion about black code formatter
Completely agree with you. Black is non pep8 compliant and breaks fundamental visual cues. I already wrote at length about it and you can find it in my history. Black should be avoided. Not because it's a different formatting style. But because it's a different formatting style that is _inferior_ to pep8 in providing visual cues. More on reddit.com
🌐 r/Python
53
3
February 2, 2020
python - How to automating Code Formatting in VSCode for Jupyter Notebooks with Black Formatter? - Stack Overflow
I've been enjoying the convenience of the Black Formatter extension in Visual Studio Code, especially its "Format on Save" feature for Python files. Being able to automatically format my ... More on stackoverflow.com
🌐 stackoverflow.com
Is the damage psf/Black has done to the community reversible?
capable narrow wistful simplistic bells historical bright possessive disagreeable birds This post was mass deleted and anonymized with Redact More on reddit.com
🌐 r/Python
133
0
July 26, 2024
🌐
Orchestra
getorchestra.io › guides › black-formatter-not-working-vscode-fixes
Black Formatter Not Working: VSCode Fixes | Orchestra
December 10, 2024 - The Black Formatter is a widely-used tool among Python developers for automatically formatting code to ensure consistency and readability. When integrated with VSCode, it streamlines the development process by enforcing code style guidelines on save.
🌐
Read the Docs
black.readthedocs.io › en › stable › the_black_code_style › current_style.html
The Black code style - Black 26.3.0 documentation
Black aims for consistency, generality, readability and reducing git diffs. Similar language constructs are formatted with similar rules. Style configuration options are deliberately limited and rarely added. Previous formatting is taken into account as little as possible, with rare exceptions ...
🌐
Vercel
black.vercel.app
Black Playground
Playground for Black, the uncompromising Python code formatter.
🌐
Hacker News
news.ycombinator.com › item
Black, the uncompromising Python code formatter, is stable | Hacker News
January 1, 2022 - Change log: https://black.readthedocs.io/en/latest/change_log.html · Going forward we'll follow our stability policy (https://black.readthedocs.io/en/latest/the_black_code_style/...)
🌐
PyPI
pypi.org › project › black
black · PyPI
The uncompromising code formatter. ... 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 ...
      » pip install black
    
Published   Mar 12, 2026
Version   26.3.1
Find elsewhere
🌐
Black
black.readthedocs.io
Black 26.3.0 documentation
Black makes code review faster by producing the smallest diffs possible. 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.
🌐
Medium
medium.com › technology-hits › embrace-clean-code-with-black-pythons-opinionated-formatter-that-just-works-4c0f99759794
Embrace Clean Code with Black: Python’s Opinionated Formatter That Just Works | by Sahdev Garg | Technology Hits | Medium
November 14, 2024 - Black isn’t just another linter; it’s a formatter with an attitude. Unlike tools like flake8 or pycodestyle, which detect formatting issues but leave you to fix them, Black doesn’t ask — it fixes.
🌐
Reddit
reddit.com › r/python › my unpopular opinion about black code formatter
r/Python on Reddit: My unpopular opinion about black code formatter
February 2, 2020 - Whatever id do, black will always format that import statement into one line (instead of using MY parantheses and the way, which is suggested in pep8) from .views import CategoryListCreateAPIView, EventDetailAPIView, EventListCreateAPIView · Flake8 complains about the 88 chars of course. that sucks. Prettier Rust: An opinionated code formatter that autocorrects bad syntax
🌐
Packetcoders
packetcoders.io › whats-the-difference-black-vs-ruff
Black vs Ruff - What's the difference?
November 2, 2023 - For a good few years, Black has been the defacto Python formatter. With the recent release of a new tool called Ruff, which describes itself as: An extremely fast Python linter and code formatter ...
🌐
Luminous Men
luminousmen.com › post › my-unpopular-opinion-about-black-code-formatter
My unpopular opinion about black code formatter
July 25, 2024 - But even PEP8 itself has devoted a whole paragraph to "readability counts" and mentions that a style guide helps avoid bugs as it introduces best practices to avoid code smells. And the key point — consistency is only important as it improves readability. But Black is not about this at all, Black removes visual cues, as it is written in the documentation 'It doesn't take previous formatting into account.
🌐
Curiousity
curiousity.ca › 2024 › best-practices-black
Best practices in practice: Black, the Python code formatter | Curiousity?
September 27, 2024 - Black’s tagline is “the uncompromising Python code formatter” and it pretty much is what it says on the tin: it can be used to automatically format Python code, and it’s reasonably opinionated about how it’s done with very few options to change. It starts with pep8 compliance (that’s ...
🌐
Reddit
reddit.com › r/python › is the damage psf/black has done to the community reversible?
r/Python on Reddit: Is the damage psf/Black has done to the community reversible?
July 26, 2024 -

I really don't understand why the Python Black formatter seems to be so popular. What is the point of a non-configurable and highly biased code formatter? I see no benefit in making all the code in the world look the same. They claim they are ending discussions about code formatting, but in reality they have sparked the biggest debate ever in the Python community with their subjective and often contradictory methods that have evolved over decades of established practices without the ability to configure the formatter. [1][2] The single/double quote disaster is just the most prominent example.

There are people out there who put readability above consistency with every other code base in the world that they will never come into contact with.

What bothers me most is the detachment of the Black developers, who dismiss all objections to their style choices as if they were opinions, and end every discussion by saying, you are just expressing an opinion and we prefer ours. But that is not true, there were many reasons, objectively measurable reasons, why this or that decision is better. Someone else might weigh these reasons differently and therefore come to a different conclusion. But the arguments used to enforce Black's decisions have never stood the test of time in a factual discussion.

I also notice that younger developers (< 35 years) are more likely to accept this approach than the more experienced ones.

[1] https://github.com/psf/black/issues/1252

[2] https://github.com/psf/black/issues/373

🌐
Medium
akshay-jain.medium.com › pycharm-black-with-formatting-on-auto-save-4797972cf5de
Pycharm + Black with Formatting on Auto-save | by Akshay Jain | Medium
June 11, 2021 - Pycharm + Black with Formatting on Auto-save So, lately, I’ve been working with Black for Python code formatting. Pretty cool huh! I’ve seen Black do wonders to my code. It made my (already …
Top answer
1 of 7
111

This is due to the default line length for black being longer than you'd like – 88 characters per line.

To decrease the line length, you can use the --line-length flag as documented here:

https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html

For example:

$ black --line-length 80 example.py

Black explains the --line-length setting in more detail here:

https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length

Line length

You probably noticed the peculiar default line length. Black defaults to 88 characters per line, which happens to be 10% over 80. This number was found to produce significantly shorter files than sticking with 80 (the most popular), or even 79 (used by the standard library). In general, 90-ish seems like the wise choice.

If you're paid by the line of code you write, you can pass --line-length with a lower number. Black will try to respect that. However, sometimes it won't be able to without breaking other rules. In those rare cases, auto-formatted code will exceed your allotted limit.

You can also increase it, but remember that people with sight disabilities find it harder to work with line lengths exceeding 100 characters. It also adversely affects side-by-side diff review on typical screen resolutions. Long lines also make it harder to present code neatly in documentation or talk slides.

Emphasis on the final paragraph.

I'd recommend just keeping the default settings. The beauty of Black is that it chooses for you, and therefor preempts any arguments about which way is "best".

2 of 7
72

This is now possible by adding a trailing comma to your last argument.

In your example you would write instead:

def example_function(
    arg_1: str, 
    arg_2: bool, 
    arg_3: int = 0, 
    arg_4: int = 1, 
    arg_5: float = 0.0, # <-- Notice the trailing comma
):
🌐
YouTube
youtube.com › watch
How to Install & Configure Black Formatter in VS Code for Python - YouTube
Make your Python code beautiful effortlessly! This quick guide shows you how to set up the Black Formatter in VS Code. Discover how to enable auto-formatting...
Published   July 24, 2025
🌐
DEV Community
dev.to › adamlombard › how-to-use-the-black-python-code-formatter-in-vscode-3lo0
VSCode: Using Black to automatically format Python - DEV Community
April 4, 2024 - Black is "the uncompromising Python code formatter." It can be configured to automatically format your code whenever you save a file in VSCode.