Skip to main content

Run `black` on python code blocks in documentation files

Project description

Build Status Azure DevOps coverage


Run black on python code blocks in documentation files.


pip install blacken-docs


blacken-docs provides a single executable (blacken-docs) which will modify .rst / .md / .tex files in place.

It currently supports the following black options:

  • -l / --line-length
  • -t / --target-version
  • -S / --skip-string-normalization

Following additional parameters can be used:

  • -E / --skip-errors

blacken-docs will format code in the following block types:


    def hello():
        print("hello world")


    .. code-block:: python

        def hello():
            print("hello world")


def hello():
    print("hello world")

(markdown/rst in python docstrings)

def f():
    """docstring here

    .. code-block:: python

        print("hello world")

    print("hello world")

usage with pre-commit

See pre-commit for instructions

Sample .pre-commit-config.yaml:

-   repo:
    rev: v1.7.0
    -   id: blacken-docs
        additional_dependencies: [black==...]

Since black is currently a moving target, it is suggested to pin black to a specific version using additional_dependencies.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for blacken-docs, version 1.7.0
Filename, size File type Python version Upload date Hashes
Filename, size blacken_docs-1.7.0-py2.py3-none-any.whl (4.8 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size blacken_docs-1.7.0.tar.gz (4.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page