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, usepip install "black[jupyter]".Usage: Format a file or directory with
black {source_file_or_directory}. Run as a package withpython -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
--fastto 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.providertoblackandeditor.formatOnSavetotrue.PyCharm: Use the "External Tools" feature to run Black on save.
GitHub Actions: Use the
run-black-formatteraction 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.
Black, the uncompromising Python code formatter, is stable
My unpopular opinion about black code formatter
python - How to automating Code Formatting in VSCode for Jupyter Notebooks with Black Formatter? - Stack Overflow
Is the damage psf/Black has done to the community reversible?
Videos
» pip install black
After setting up Black formatter, you could search for Notebook: formatOnSave and Notebook: formatOnCellExecution in settings(Ctrl+,).
Check these options, You can make formatter work when you save the file in jupyter notebook.


Found this solution online:
pip install black[jupyter]
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
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-lengthwith 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".
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
):