Adding extensions#

JupyterLite reuses the same system of prebuilt extensions as in JupyterLab 3.0+. Prebuilt extensions are also sometimes called federated extensions. In JupyterLab they can be installed via pip and conda without rebuilding the whole JupyterLab application.

All the applications shipped with JupyterLite by default are built with JupyterLab components. This allows for most of the existing third-party JupyterLab extensions to also work with JupyterLite.

Adding new extensions from an environment#

Creating a new environment#

The easiest way to add new extensions is to use the JupyterLite CLI in a Python environment where extensions have already been installed.

You can choose the tool of your choice to manage these dependencies, such as pip, conda or mamba. For conda and mamba they are typically defined in environment.yml, and in requirements.txt for pip.

If you want to build a JupyterLite website locally on your machine, it is preferable to first create a new environment.

This can be done with the venv module:

python -m venv .
source bin/activate

Or with conda / mamba:

mamba create -n my-jupyterlite-deployment -c conda-forge python -y
mamba activate my-jupyterlite-deployment

Installing the extensions in the environment#

As an example let’s use the following requirements.txt:

jupyterlab-tour
jupyterlab-night

This file lists two extensions, one of them is a theme. Run the following command to install them:

python -m pip install -r requirements.txt

If you have jupyterlab installed, you can verify they are correctly installed with:

jupyter labextension list

Which should return something similar to the following:

JupyterLab v4.*.*
PREFIX/share/jupyter/labextensions
        jupyterlab-tour  v4.0.1 enabled OK
        jupyterlab-night v0.4.0 enabled OK

Build the JupyterLite website#

Now we need to produce the JupyterLite archive that will include these extensions. This can be done with the following command:

jupyter lite build

When you run jupyter lite build, all pre-built extensions in your JupyterLab environment, e.g. {sys.prefix}/share/jupyter/labextensions will be:

  • copied to {output-dir}/extensions

  • have their theme assets copied to {output-dir}/build/themes

Managing the extensions shipped with the website#

In the JupyterLab interface, the Extension Manager available in the left sidebar lists the extensions shipped with the website, with their versions. Since the extensions are bundled at build time, they cannot be installed or uninstalled from the browser.

Users can disable and enable these extensions from the Extension Manager, and single plugins from the Advanced Plugin Manager available in the command palette. These choices are stored in the browser with the user settings, and apply to all the apps of the website once the page is reloaded. To reset them, use the “Clear Browser Data” command in the Help menu and select “Settings and preferences”.

The extensions and plugins listed in the disabledExtensions of the website cannot be enabled from the browser: such extensions are not shown in the Extension Manager, and such plugins are locked in the Plugin Manager. The plugins providing the in-browser services, such as settings and kernels, are locked too.

The Extension Manager is displayed by default. To hide it, disable the @jupyterlab/extensionmanager-extension:plugin plugin with the following jupyter-lite.json:

{
  "jupyter-lite-schema-version": 0,
  "jupyter-config-data": {
    "disabledExtensions": ["@jupyterlab/extensionmanager-extension:plugin"]
  }
}

Note

The enabled setting of the Extension Manager has no effect in JupyterLite, since it only applies to an Extension Manager that can install extensions. Use disabledExtensions instead, as described above.

The case of Jupyter Widgets and custom renderers#

Some extensions like Jupyter Widgets and custom renderers also need a Python package to be installed at runtime when working with a notebook. This is for example the case with ipyleaflet, bqplot or plotly.

To install the frontend extensions, simply add it to the list of requirements. For example continuing from the requirements.txt file defined above:

jupyterlab-tour
jupyterlab-night
ipywidgets
bqplot
plotly

The end users of your JupyterLite instance will still need to install the dependencies at runtime in their notebooks with the IPython-compatible %pip magic:

%pip install -q ipywidgets bqplot plotly

which translates to:

import piplite

await piplite.install(["ipywidgets", "bqplot", "plotly"])

Avoid the drift of versions between the frontend extension and the Python package#

In some situations, the versions of the packages installed at runtime with %pip install or piplite.install might not be compatible with the deployed frontend extension anymore. This can for example happen when a JupyterLite website was built and deployed a couple of weeks ago, and new versions of the Python packages were released since. In that case the frontend extensions have not been updated since they are still available as static files as part of the deployment.

One way to avoid this mismatch is to pin the dependencies more explicitly. For example:

ipywidgets==7.7.0
bqplot==0.12.30
plotly==5.8.0

The user-facing code in the notebook will then also have to use the same versions to stay compatible:

%pip install -q "ipywidgets==7.7.0" "bqplot==0.12.30" "plotly==5.8.0"

which translates to:

import piplite

await piplite.install(["ipywidgets==7.7.0", "bqplot==0.12.30", "plotly==5.8.0"])

This is unfortunately a little bit brittle but does the job for now. There is chance this will be improved in future versions of JupyterLite.

Check out the guide on configuring the piplite URLs if you want to have more control on your dependencies.

How to know if an extension is compatible with JupyterLite?#

A good starting point for extensions that might work is the JupyterLab issue Extension Compatibility with 4.0 (#14590). Additionally, this site demonstrates a few extensions.

Advanced extension configuration#

If you are looking for more options to configure extensions, check out the dedicated guide on Advanced extension configuration.