JupyterLab Server Components

raw JSON →
2.28.0 verified Tue May 12 auth: no python install: verified

jupyterlab-server provides a set of REST API handlers and utilities that serve as the backend components for JupyterLab and similar applications. It acts as an intermediary layer between JupyterLab and Jupyter Server, allowing for the creation of custom JupyterLab-like environments. The library maintains an active development pace with frequent updates, often on a monthly or bi-monthly release cycle.

pip install jupyterlab-server
breaking In version 2.28.0, a typo was fixed in the default traitlet for the template directory, changing `template_dir` to `templates_dir`. Configurations explicitly overriding `template_dir` in earlier versions will need to be updated to `templates_dir` to maintain functionality.
fix Update `c.ServerApp.template_dir` to `c.ServerApp.templates_dir` in your Jupyter configuration files (e.g., `jupyter_jupyterlab_server_config.py`).
gotcha `jupyterlab-server` is primarily a component library providing backend services for JupyterLab and JupyterLab-like applications. It is not designed as a standalone end-user application. Direct programmatic use often involves extending its `ServerApp` or adding custom handlers within a larger Jupyter ecosystem context.
fix When using `jupyterlab-server`, understand its role as a building block. For end-user scenarios, typically install `jupyterlab` itself. For extensions, follow the Jupyter Server extension development guidelines.
gotcha When migrating server extensions from `notebook` (Classic Notebook) to `jupyter_server` (which `jupyterlab-server` builds upon), import paths for server modules may have changed. Code directly importing server components from the `notebook` package will need adjustment.
fix Consult the `jupyter_server` migration guides for updating import paths and extension loading mechanisms. Use `jupyterlab_server` specific imports where available.
deprecated JupyterLab v3.6 and later requires `jupyter_server v2.0` for Real-Time Collaboration features. While `jupyterlab-server` itself might support older `jupyter_server` versions for basic functionality, major new features in the ecosystem often mandate newer server versions.
fix Ensure `jupyter_server` is updated to at least version 2.0 when aiming to use Real-Time Collaboration with JupyterLab. Check `jupyterlab-server`'s `jupyter_server` dependency range for compatibility.
pip install jupyterlab-server[openapi]
python os / libc variant status wheel install import disk
3.10 alpine (musl) jupyterlab-server wheel - 9.78s 103.6M
3.10 alpine (musl) jupyterlab-server - - 9.71s 103.4M
3.10 alpine (musl) openapi wheel - 9.38s 110.1M
3.10 alpine (musl) openapi - - 9.35s 109.9M
3.10 slim (glibc) jupyterlab-server wheel 9.6s 7.26s 101M
3.10 slim (glibc) jupyterlab-server - - 6.63s 101M
3.10 slim (glibc) openapi wheel 11.5s 7.35s 107M
3.10 slim (glibc) openapi - - 6.97s 107M
3.11 alpine (musl) jupyterlab-server wheel - 9.13s 111.8M
3.11 alpine (musl) jupyterlab-server - - 10.61s 111.6M
3.11 alpine (musl) openapi wheel - 9.18s 119.3M
3.11 alpine (musl) openapi - - 10.58s 119.0M
3.11 slim (glibc) jupyterlab-server wheel 10.0s 8.51s 109M
3.11 slim (glibc) jupyterlab-server - - 8.44s 109M
3.11 slim (glibc) openapi wheel 11.6s 8.42s 117M
3.11 slim (glibc) openapi - - 8.38s 116M
3.12 alpine (musl) jupyterlab-server wheel - 8.99s 102.1M
3.12 alpine (musl) jupyterlab-server - - 10.48s 101.9M
3.12 alpine (musl) openapi wheel - 9.06s 109.4M
3.12 alpine (musl) openapi - - 10.35s 109.1M
3.12 slim (glibc) jupyterlab-server wheel 8.3s 9.65s 99M
3.12 slim (glibc) jupyterlab-server - - 10.20s 99M
3.12 slim (glibc) openapi wheel 9.8s 9.19s 107M
3.12 slim (glibc) openapi - - 10.10s 106M
3.13 alpine (musl) jupyterlab-server wheel - 8.31s 101.9M
3.13 alpine (musl) jupyterlab-server - - 8.91s 101.6M
3.13 alpine (musl) openapi wheel - 9.14s 109.2M
3.13 alpine (musl) openapi - - 9.20s 108.8M
3.13 slim (glibc) jupyterlab-server wheel 8.2s 8.66s 99M
3.13 slim (glibc) jupyterlab-server - - 9.99s 99M
3.13 slim (glibc) openapi wheel 9.5s 8.67s 106M
3.13 slim (glibc) openapi - - 9.68s 106M
3.9 alpine (musl) jupyterlab-server wheel - 10.14s 103.7M
3.9 alpine (musl) jupyterlab-server - - 10.01s 103.6M
3.9 alpine (musl) openapi wheel - 10.17s 110.2M
3.9 alpine (musl) openapi - - 9.96s 110.1M
3.9 slim (glibc) jupyterlab-server wheel 11.1s 9.57s 101M
3.9 slim (glibc) jupyterlab-server - - 8.40s 101M
3.9 slim (glibc) openapi wheel 13.0s 9.24s 108M
3.9 slim (glibc) openapi - - 8.82s 107M

This quickstart illustrates how to define and conceptually register a custom API handler using `jupyterlab-server` components. Typically, `jupyterlab-server` is extended within a larger Jupyter application (like JupyterLab) via a server extension. The `load_jupyter_server_extension` function is the entry point for such extensions, where custom Tornado `web.RequestHandler`s (here, `LabHandler`) are added to the server's web application.

import os
from tornado import web
from jupyterlab_server.server import ServerApp
from jupyterlab_server.handlers import LabHandler

# Define a simple custom handler
class MyCustomHandler(LabHandler):
    @web.authenticated
    def get(self, path=''):
        self.finish(f"Hello from My Custom Handler! Path: {path}")

# This function would typically be in a server extension module
# (e.g., `my_extension.py`) and discovered by Jupyter Server.
def load_jupyter_server_extension(server_app: ServerApp):
    host_pattern = ".*$"
    base_url = server_app.base_url
    route_pattern = web.url(f"/{os.environ.get('MY_CUSTOM_ROUTE_PREFIX', 'my-api')}(.*)", MyCustomHandler)
    server_app.web_app.add_handlers(host_pattern, [route_pattern])
    server_app.log.info(f"MyCustomHandler enabled at {base_url}my-api")

# To run this for testing, you'd integrate it with a Jupyter Server setup.
# This block is illustrative and not a direct executable for end-users
# as jupyterlab-server is a component library.
# For a real setup, this would be loaded as a server extension.
# Example command to launch JupyterLab with this extension:
# jupyter lab --ServerApp.extra_static_paths='["$(pwd)"]' \
#  --ServerApp.jpserver_extensions='{"my_extension": true}'

# For testing purposes (not how it's usually run in production):
# if __name__ == "__main__":
#     from jupyter_server.serverapp import ServerApp as _JupyterServerApp
#     class CustomLabServerApp(_JupyterServerApp):
#         def initialize_settings(self):
#             super().initialize_settings()
#             load_jupyter_server_extension(self)
#     CustomLabServerApp.launch_instance()