Skip to content

Using the jupyterlab services API

Rich Chiodo edited this page Aug 3, 2022 · 17 revisions

This page describes how the Jupyter extension uses the @jupyterlab/services npm module to connect and control Jupyter kernels.

What is it and why do we need it?

Jupyter kernels are processes that handle a set of messages called the Jupyter Messaging Protocol (or JMP for short).

In this diagram below, those messages are sent over the 0MQ portion.

We (the Jupyter Extension) need to send these messages to and from a Jupyter kernel.

The Jupyter org has provided the @jupyterlab/services npm module to help us do just that.

This npm module:

The npm module essentially handles all communication to and from a kernel so that javascript can treat the kernel like a local object.

image

Raw ZMQ

We started with the @jupyterlab/services because the first version of the Jupyter extension always talked to a notebook server, either by us starting one or the user providing one.

There were frequent issues with that and we switched to a more direct approach.

The direct (or raw as it's called elsewhere) doesn't talk to a notebook server though. Instead it talks directly to the kernels over zmq:

This means we don't have a websocket to connect to. However, since we were using the @jupyterlab/services::IKernelConnection as the standard way of communicating with kernels, we tricked jupyterlab services into thinking it was still talking to a server.

Essentially this part here:

image

Raw changes the sequence diagram to look like so:

image

In the diagram, the Notebook Server has now been replaced by a RawSocket. The implementation for this can be found here.

Note: Special services changes

Since the RawSocket is talking directly to the kernel, it needs to serialize/deserialize on its own. To facilitate this, we replace the serialization in the @jupyterlab/services with empty functions. That happens in an npm post install hook.

Futures and what they mean

Widgets

Clone this wiki locally