{"id":9859,"library":"jupyterlab-code-formatter","title":"JupyterLab Code Formatter","description":"jupyterlab-code-formatter is a JupyterLab plugin that integrates popular code formatters (like Black, isort, Ruff, yapf, autopep8) directly into the JupyterLab IDE. It allows users to format their Python code within notebooks and script files via a context menu, menu bar, or keyboard shortcuts. The current version, 3.0.3, is designed for JupyterLab 3.x and 4.x, leveraging its modern extension system. It maintains an active development cycle with regular updates.","status":"active","version":"3.0.3","language":"en","source_language":"en","source_url":"https://github.com/jupyterlab-contrib/jupyterlab_code_formatter","tags":["jupyter","jupyterlab","formatter","code-quality","linter","plugin"],"install":[{"cmd":"pip install jupyterlab_code_formatter","lang":"bash","label":"Install the extension"},{"cmd":"pip install black isort ruff","lang":"bash","label":"Install desired formatters (example)"}],"dependencies":[{"reason":"This is a JupyterLab extension and requires JupyterLab to run.","package":"jupyterlab","optional":false},{"reason":"One of the popular Python formatters supported by the extension. Must be installed separately.","package":"black","optional":true},{"reason":"One of the popular Python import sorters supported by the extension. Must be installed separately.","package":"isort","optional":true},{"reason":"A fast Python linter and formatter. Supported by the extension and must be installed separately.","package":"ruff","optional":true}],"imports":[],"quickstart":{"code":"pip install jupyterlab_code_formatter\npip install black isort ruff\n# Then, restart JupyterLab. Right-click on a cell or file to format.","lang":"bash","description":"Install the extension and your preferred code formatters (e.g., black, isort, ruff). After installation, restart your JupyterLab server. The formatting options will appear in the right-click context menu within a notebook cell or file editor, under the 'Format Code' menu, or via the 'Edit' menu. You can also configure keyboard shortcuts and default formatters in JupyterLab's Advanced Settings Editor."},"warnings":[{"fix":"Ensure your `jupyterlab-code-formatter` version matches your `jupyterlab` major version (e.g., `jupyterlab_code_formatter>=3` for `jupyterlab>=3`). Upgrade JupyterLab if necessary or downgrade the extension.","message":"JupyterLab Code Formatter versions are tied to JupyterLab major versions. Version 3.x is for JupyterLab 3.x/4.x. If you are using JupyterLab 2.x, you need to install jupyterlab-code-formatter 2.x.","severity":"breaking","affected_versions":"<3.0.0"},{"fix":"After installing `jupyterlab_code_formatter`, always run `pip install black isort ruff` (or your preferred formatters) to make them available to the extension.","message":"The `jupyterlab_code_formatter` extension itself does not include the actual code formatters (like Black, isort, Ruff). You must install your desired formatters separately in the same Python environment where JupyterLab is running.","severity":"gotcha","affected_versions":"All"},{"fix":"If the extension doesn't appear after restarting JupyterLab, try running `jupyter lab build` in your terminal and then restart JupyterLab again. Clear browser cache if issues persist.","message":"After installing or updating the extension, you might need to rebuild your JupyterLab frontend for the changes to take effect, especially with older JupyterLab versions or complex environments. The `jupyter lab build` command is often helpful.","severity":"gotcha","affected_versions":"<3.0.0 (less common in >=3.0.0)"},{"fix":"Open 'Settings' > 'Advanced Settings Editor' in JupyterLab, then select 'Code Formatter'. Ensure 'formatOnSave' or specific formatters are enabled and paths are correct if you've customized them. Save changes and restart JupyterLab if necessary.","message":"Configuration for jupyterlab-code-formatter is done via JupyterLab's 'Advanced Settings Editor', not via Python code or separate config files in your user directory. Common issues include incorrect paths or enabled formatters.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Install the missing formatter: `pip install black` (or `isort`, `ruff`, etc.). Restart JupyterLab after installation.","cause":"The specific formatter (e.g., Black) is not installed in the Python environment where JupyterLab is running.","error":"Error: Formatter 'black' not found. Please ensure 'black' is installed and available in your PATH."},{"fix":"Check for version compatibility (`jupyterlab-code-formatter` and `jupyterlab`). If versions match, try running `jupyter lab build` in your terminal, then clear your browser cache and restart JupyterLab. Ensure you've installed formatters.","cause":"The JupyterLab frontend did not properly load or enable the extension, or there's a version mismatch.","error":"JupyterLab extension is not showing up or formatting options are missing from the menu."},{"fix":"You do not need to `import jupyterlab_code_formatter` in your Python code. Install it via `pip` and interact with its features directly through the JupyterLab UI (right-click menu, Edit menu, keyboard shortcuts).","cause":"jupyterlab-code-formatter is a JupyterLab *extension* and is not meant to be imported directly into Python scripts by end-users. It's a server-side component for the JupyterLab frontend.","error":"No module named 'jupyterlab_code_formatter' when I try to import it."}]}