Skip to content
A universal code formatter for JupyterLab.
Branch: master
Clone or download
ryantam626 Merge pull request #18 from Lif3line/black_jupyter_magic_fix
Fix black formatting error when jupyter %magic present
Latest commit 68c7fb2 Apr 7, 2019
Type Name Latest commit message Commit time
Failed to load latest commit information.
jupyterlab_code_formatter Fix black formatting error when jupyter %magic present Apr 1, 2019
schema Add isort config section to schema Mar 24, 2019
style Init commit from cookie cutter Aug 12, 2018
.gitignore Ignore VS Code stuff Aug 18, 2018 Publish 0.2.0 Mar 24, 2019
LICENSE Add info about isort in README Mar 24, 2019
code-formatter-demo.gif Replace demo gif Aug 18, 2018
package-lock.json Publish 0.2.0 Mar 24, 2019
package.json Publish 0.2.0 Mar 24, 2019


npm version npm downloads code style

Code formatter for JupyterLab.


  • JupyterLab installed under Python3.6+ environment

Why Python3.6+

  • Mainly because Black requires 3.6+, and I like using Black the most;
  • Typing support requires 3.5+, and I like typing;


jupyter labextension install @ryantam626/jupyterlab_code_formatter
pip install jupyterlab_code_formatter
jupyter serverextension enable --py jupyterlab_code_formatter
# Remember to install one of the supported formatters (it's in the next section)

Installation of formatters

For jupyterlab_code_formatter to work, you would also need some formatters, three are currently supported:

  • Black;
  • YAPF;
  • Autopep8;
  • Isort;

Install at least one of them through pip install black for example (or its equivalent in other package management systems).


Assuming you do have one of the formatters installed in the Python environment that runs JupyterLab, some extra options would appear under JUPYTERLAB CODE FORMATTER, use those to apply formatting to current codecell (no multiple code cell application atm).


There are some formatter config exposed through the Jupyter Lab Advanced Settings Editor, have a browse and change it if you wish.

How about a keyboard shortcut?

Add an extra extry to your keyboard shortcuts settings with something like

    "command": "jupyterlab_code_formatter:black",
    "keys": [
        "Ctrl K",
        "Ctrl M"
    "selector": ""

This basically says "Under edit mode (detected through the selector), using the chord Ctrl K + Ctrl M, invoke the jupyterlab_code_formatter:black command". And there you have it 🎉

For Autopep8, YAPF or Isort, simply do autopep8/yapf/isort instead of black.

Using the Black formatter on Windows

You might see some errors about writing grammar tables when using the black formatter on Windows, simply manually create the directory as suggested in here and you should be good to go.


For a development install (requires npm version 4 or later), do the following in the repository directory:

npm install
npm run build
jupyter labextension link .
pip install -e .

To rebuild the package and the JupyterLab app:

npm run build
jupyter lab build
You can’t perform that action at this time.