Jupyter Black is an extension for Jupyter Notebook and Jupyter Lab that automatically beautifies Python code in cells using the Black formatter. It aims to provide an uncompromising, consistent code style directly within the interactive notebook environment. The current version is 0.4.0, and the project is actively maintained with updates released as needed to support newer Jupyter and Python versions.
pip install jupyter-blackVerified import paths — ran on the pinned version, not inferred.
To enable jupyter-black, simply import the library and call `jupyter_black.load()` in a code cell. This can be customized with `line_length`, `verbosity`, and `target_version` arguments. Once loaded, code cells will be formatted automatically upon execution. Alternatively, you can use the IPython magic command `%load_ext jupyter_black` for default settings.
Upgrade your JupyterLab to version 4+ or Jupyter Notebook to version 7+, or pin `jupyter-black` to an older version like `0.3.4` (e.g., `pip install jupyter-black==0.3.4`).
Ensure cells contain valid Python syntax for formatting. For cells with magics or mixed content, manual formatting may be required, or the magics should be placed on separate lines if possible.
Always install using `pip install jupyter-black` (the pypi.org/project/jupyter-black package) and verify the GitHub repository `n8henrie/jupyter-black` for official documentation and updates.
Escape the brackets with a backslash: `pip install black\[jupyter\]`. Note that `jupyter-black` (this library) is a separate project from Black's own Jupyter integration, and does not require this extra.
Correct any syntax errors in the cell. Once the code is syntactically valid, `jupyter-black` will format it on the next execution.
Ensure `jupyter-black` is installed in the correct environment (`pip install jupyter-black`). If issues persist, verify your JupyterLab/Notebook version meets the `jupyter-black` requirements (JupyterLab >=4 / Notebook >=7) or consider using an older `jupyter-black` version. Restarting the Jupyter kernel or server can also resolve transient loading issues.