Skip to content


Black is a style guide enforcement tool.

You can use this cookiecutter template to create a python project with black already configured.


pip install black


Its configuration is stored in pyproject.toml.

File: pyproject.toml

# Example configuration for Black.

# NOTE: you have to use single-quoted strings in TOML for regular expressions.
# It's the equivalent of r-strings in Python.  Multiline strings are treated as
# verbose regular expressions by Black.  Use [ ] to denote a significant space
# character.

line-length = 88
target-version = ['py36', 'py37', 'py38']
include = '\.pyi?$'
exclude = '''
  | \.git
  | \.hg
  | \.mypy_cache
  | \.tox
  | \.venv
  | _build
  | buck-out
  | build
  | dist
  # The following are specific to Black, you probably don't want those.
  | blib2to3
  | tests/data
  | profiling

You can use it both with:

  • The Vim plugin

  • Pre-commit:

    File: .pre-commit-config.yaml

    - repo:
      rev: stable
        - id: black
          language_version: python3.7
  • Github Actions:

    File: .github/workflows/lint.yml

    name: Lint
    on: [push, pull_request]
        runs-on: ubuntu-latest
          - uses: actions/checkout@v2
          - uses: actions/setup-python@v2
          - name: Black
            uses: psf/black@stable

Split long lines

If you want to split long lines, you need to use the --experimental-string-processing flag. I haven't found how to set that option in the config file.

Disable the formatting of some lines

You can use the comments # fmt: off and # fmt: on


Last update: 2020-12-11