A simple extension for Jupyter Notebook and Jupyter Lab to beautify Python code automatically using Black. Fork of dnanhkhoa/nb_black.
Slowing down. Last release over 2 years ago, little activity since. Fine for existing code; think twice for a new project.
pip install jupyter-blackjupyter-black
A simple extension for Jupyter Notebook and Jupyter Lab to beautify Python code automatically using Black. Fork of dnanhkhoa/nb_black with a few minor modifications:
Features
Once loaded, automatically format syntactically correct jupyter cells with
black once they are run.
Enhancements compared to dnanhkhoa/nb_black:
- Configurability:
- Try to read black config from
pyproject.tomlif available - Override settings such as line length and
black.TargetVersionif desired
- Try to read black config from
- Uses
black.format_cellto greatly simplify the codebase - Adds tests
- Slightly more responsive (no longer requires
setTimeoutand a delay) - Free software: MIT
Introduction
black is an extremely popular python formatter. Jupyter is an
awesome way to run python. This extension helps you automatically blacken
your jupyter.
Dependencies
- Python >= 3.7
- See
setup.cfg
Quickstart
python3 -m venv .venv && source ./.venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install jupyter-black jupyter
python3 -m jupyter notebook
From here, there are two ways to load the extension:
Configurable (recommended):
import jupyter_black
jupyter_black.load()
To look at configuration options:
jupyter_black.load??