|
1 |
| -# distributed_jupyter_demo |
| 1 | +# Distributed Jupyter Kernel Demo |
2 | 2 |
|
3 | 3 | [](https://github.com/QuantStack/distributed-jupyter-demo/actions/workflows/build.yml)
|
4 | 4 |
|
5 |
| -A JupyterLab extension. |
| 5 | +This project demonstrates a **proof of concept** for using a custom JupyterLab plugin to connect to a **remote Jupyter server's kernel manager** using a shared token. It shows how one JupyterLab frontend (Server B) can start and interact with kernels running on another backend Jupyter server (Server A). |
6 | 6 |
|
7 |
| -## Requirements |
| 7 | +--- |
8 | 8 |
|
9 |
| -- JupyterLab >= 4.0.0 |
| 9 | +## 🧩 What This Demo Does |
10 | 10 |
|
11 |
| -## Install |
| 11 | +- **Server A** is a Jupyter Server that exposes a kernel manager (with CORS enabled). |
| 12 | +- **Server B** is a JupyterLab instance running a custom **ServiceManagerPlugin**. |
| 13 | +- The plugin in Server B creates its own `KernelManager` that connects to Server A using a shared token and URL. |
| 14 | +- Kernels started from Server B appear and run on Server A. |
12 | 15 |
|
13 |
| -To install the extension, execute: |
| 16 | +This can be a helpful starting point for building distributed or decoupled architectures in the Jupyter ecosystem (e.g., connecting to remote compute backends, multi-user systems, etc.). |
14 | 17 |
|
15 |
| -```bash |
16 |
| -pip install distributed_jupyter_demo |
17 |
| -``` |
| 18 | +--- |
18 | 19 |
|
19 |
| -## Uninstall |
| 20 | +## 🔧 Local Setup (Without Docker) |
20 | 21 |
|
21 |
| -To remove the extension, execute: |
| 22 | +### 1. Create a Conda/mamba Environment and Install Dependencies |
22 | 23 |
|
23 | 24 | ```bash
|
24 |
| -pip uninstall distributed_jupyter_demo |
25 |
| -``` |
| 25 | +conda create -n distributed-jupyter-demo python=3.11 -y |
| 26 | +conda activate distributed-jupyter-demo |
26 | 27 |
|
27 |
| -## Contributing |
| 28 | +pip install -e . && pip install jupyterlab |
| 29 | +jlpm install |
| 30 | +jupyter labextension develop . --overwrite |
| 31 | +jupyter lab build |
28 | 32 |
|
29 |
| -### Development install |
| 33 | +``` |
| 34 | + |
| 35 | +--- |
30 | 36 |
|
31 |
| -Note: You will need NodeJS to build the extension package. |
| 37 | +### 2. Start the Servers (In Separate Terminals) |
32 | 38 |
|
33 |
| -The `jlpm` command is JupyterLab's pinned version of |
34 |
| -[yarn](https://yarnpkg.com/) that is installed with JupyterLab. You may use |
35 |
| -`yarn` or `npm` in lieu of `jlpm` below. |
| 39 | +**Terminal 1: Server A** |
36 | 40 |
|
37 | 41 | ```bash
|
38 |
| -# Clone the repo to your local environment |
39 |
| -# Change directory to the distributed_jupyter_demo directory |
40 |
| -# Install package in development mode |
41 |
| -pip install -e "." |
42 |
| -# Link your development version of the extension with JupyterLab |
43 |
| -jupyter labextension develop . --overwrite |
44 |
| -# Rebuild extension Typescript source after making changes |
45 |
| -jlpm build |
| 42 | +jupyter server --port 8888 --ServerApp.token=abc123 --ServerApp.allow_origin='http://localhost:8889' |
46 | 43 | ```
|
47 | 44 |
|
48 |
| -You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension. |
| 45 | +**Terminal 2: Server B** |
49 | 46 |
|
50 | 47 | ```bash
|
51 |
| -# Watch the source directory in one terminal, automatically rebuilding when needed |
52 |
| -jlpm watch |
53 |
| -# Run JupyterLab in another terminal |
54 |
| -jupyter lab |
| 48 | +jupyter lab --port 8889 --ServerApp.token=abc123 |
55 | 49 | ```
|
56 | 50 |
|
57 |
| -With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt). |
| 51 | +Then open your browser at **http://localhost:8889/lab**. The kernel plugin will automatically start a kernel on Server A. |
58 | 52 |
|
59 |
| -By default, the `jlpm build` command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command: |
| 53 | +You can confirm the kernel was created by checking **http://localhost:8888/api/kernels**. |
60 | 54 |
|
61 |
| -```bash |
62 |
| -jupyter lab build --minimize=False |
63 |
| -``` |
| 55 | +## 🐳 Run with Docker |
64 | 56 |
|
65 |
| -### Development uninstall |
| 57 | +This project comes with a ready-to-use Docker and Docker Compose setup. |
| 58 | +You will need to have **Docker** installed in your system. |
| 59 | + |
| 60 | +### 1. Build and Start the Servers |
66 | 61 |
|
67 | 62 | ```bash
|
68 |
| -pip uninstall distributed_jupyter_demo |
| 63 | +docker compose up --build |
69 | 64 | ```
|
70 | 65 |
|
71 |
| -In development mode, you will also need to remove the symlink created by `jupyter labextension develop` |
72 |
| -command. To find its location, you can run `jupyter labextension list` to figure out where the `labextensions` |
73 |
| -folder is located. Then you can remove the symlink named `distributed-jupyter-demo` within that folder. |
| 66 | +This launches: |
| 67 | + |
| 68 | +- **http://localhost:8888** → Server A (backend kernel server) |
| 69 | +- **http://localhost:8889** → Server B (JupyterLab frontend with plugin) |
| 70 | + |
| 71 | +After going to **http://localhost:8889/lab**, Server B will start a kernel on Server A when loaded and you can see it in **http://localhost:8888/api/kernels**. |
| 72 | + |
| 73 | +## 💡 Notes |
| 74 | + |
| 75 | +This demo uses a shared token (abc123) to authenticate both servers. In production, proper security measures must be taken. |
74 | 76 |
|
75 |
| -### Packaging the extension |
| 77 | +CORS is enabled on Server A to allow requests from Server B. |
76 | 78 |
|
77 |
| -See [RELEASE](RELEASE.md) |
| 79 | +This setup assumes both servers are running on the same host, but the architecture can be adapted for different machines or containers. |
0 commit comments