Jupyter Language Server Protocol Server Extension
jupyter-lsp acts as a multi-language server WebSocket proxy for Jupyter Notebook and JupyterLab servers. It enables advanced IDE-like features such as code navigation, hover suggestions, linters, and autocompletion in Jupyter environments by leveraging the Language Server Protocol (LSP). It works in conjunction with a frontend extension, typically `jupyterlab-lsp`, and specific language servers (e.g., `python-lsp-server`). The library is actively maintained, with version 2.3.0 being the current stable release, supporting Python >=3.8.
Warnings
- gotcha Installing `jupyter-lsp` alone is not enough; you must also install a separate frontend extension (like `jupyterlab-lsp` for JupyterLab) AND at least one language server (e.g., `python-lsp-server` for Python) to get any LSP features. `jupyter-lsp` is only the backend proxy.
- gotcha JupyterLab (and sometimes Jupyter Notebook) must be restarted after installing `jupyter-lsp` and `jupyterlab-lsp` for the extensions and language servers to be properly recognized and activated.
- gotcha For Python, disabling Jedi (e.g., `%config Completer.use_jedi = False` in IPython or in `ipython_config.py`) can prevent conflicts and improve autocompletion performance when using LSP servers like `python-lsp-server` (which often use Jedi internally).
- breaking `jupyter-lsp` versions 0.x were designed for Jupyter Notebook Server, while versions 1.x and above are for Jupyter Server. Installing `jupyter-lsp` 2.x with an older Jupyter Notebook environment might lead to unexpected behavior or failure to load.
- breaking Configuration keys for language servers have changed over time. For example, `language_servers` became `languageServers` and `pyls.serverSettings` became `pylsp.configuration`. Using old configuration keys can prevent language servers from loading or behaving as expected.
- gotcha By default, Jupyter Server might restrict access to files outside its root directory. For LSP features like 'Jump to Definition' to work with system-wide installed packages or virtual environments, you might need to create a symlink to your system root (e.g., `.lsp_symlink` in your Jupyter root) or configure `jupyter_server_config.py` to allow broader file access.
Install
-
pip install jupyter-lsp jupyterlab-lsp 'jupyterlab>=4.1.0' python-lsp-server -
conda install -c conda-forge jupyter-lsp jupyterlab-lsp 'jupyterlab>=4.1.0' python-lsp-server
Imports
- jupyter_lsp
jupyter-lsp is primarily a server extension and not typically imported directly in user-facing Python code within a notebook or script for its core functionality.
Quickstart
# Install jupyter-lsp and the JupyterLab frontend extension
pip install jupyter-lsp jupyterlab-lsp 'jupyterlab>=4.1.0'
# Install a language server for Python (e.g., python-lsp-server)
pip install python-lsp-server
# If using other languages, install their respective LSP servers, e.g., for R:
# Rscript -e 'install.packages("languageserver")'
# After installation, restart your JupyterLab instance to enable the extensions.
# You can then verify the installation and configure language servers via:
# JupyterLab Settings -> Settings Editor -> Language Servers (Experimental)
# Example of how you might enable the server extension if not auto-detected (less common now):
# jupyter server extension enable jupyter_lsp --py --sys-prefix
# To verify server extensions are enabled (run in terminal):
# jupyter server extension list