New to Black? Don‘t worry, you’ve found the perfect place to get started!
Before using Black on some of your code, it might be a good idea to first understand how Black will format your code. Black isn't for everyone and you may find something that is a dealbreaker for you personally, which is okay! The current Black code style is described here.
If you want a quick taste of Black without creating a file first, format a snippet from the command line:
black --code "x = { 'a':1,'b':2 }"
Black can be installed by running pip install black. It requires Python 3.10+ to run.
If you use pipx, you can install Black with pipx install black.
If you want to format Jupyter Notebooks, install with pip install "black[jupyter]". See the Jupyter Notebooks guide for more details.
If you can't wait for the latest hotness and want to install from GitHub, use:
pip install git+https://github.com/psf/black
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}...
Took a look at the Black code style and tried out Black? Fantastic, you're ready for more. Why not explore some more on using Black by reading Usage and Configuration: The basics. Alternatively, you can check out the Introducing Black to your project guide.