🪐 📄 Jupyter Server Nbmodel
Stop losing your outputs to session timeouts or network loss.
Your cells run on the server, so a reload, a closed laptop or a dropped connection no longer costs you an execution — and the outputs are still there when you come back.
📖 Documentation · 🔀 Output reconciliation · 💬 Community
- ⚡ Durable execution — a cell keeps running with no browser connected to it.
- 🖥️ Terminal-faithful outputs — progress bars overwrite their line, as they should.
- 🤖 Agent ready — a REST API to run cells and read outputs, so an agent works from the same Notebook you do.
Your agent can now reach these Notebooks without running anything. The Managed
Jupyter MCP Server, operated by Datalayer, is at https://mcp.datalayer.run/mcp — durable execution included, so a cell keeps running after the agent disconnects.
Claude Code connects with one command through the Datalayer plugin.
→ Datalayer plugin for Claude Code
Free and open source, BSD 3-Clause — install it in your own Jupyter, no account needed. Built and maintained by Datalayer, where the same durable execution powers always-on Notebooks that humans and AI agents work in together.
Side-by-side comparison: Without jupyter_server_nbmodel (left), notebook execution stops when reloading the page; with jupyter_server_nbmodel (right), execution continues uninterrupted even after reload.
A Jupyter Server extension to execute code from the server-side Nbmodel to keep your sessions and outputs active.
This extension is composed of a Python package named jupyter_server_nbmodel
for the server extension and a NPM package named @datalayer/jupyter-server-nbmodel
for the frontend extension. After installing the extension, run the snippet below in JupyterLab to try it.
import time
for i in range(1, 1000):
print(i)
time.sleep(1)
Streaming outputs also work with tqdm, whose progress bar overwrites its line
instead of printing one line per update.
from tqdm import tqdm # Standard tqdm, not tqdm.notebook
import time
for i in tqdm(range(100)):
time.sleep(0.1) # Simulate long-running process
Requirements
- Jupyter Server
>=2.0.1,<3. - JupyterLab or Jupyter Notebook 7.
- Optional but recommended for full live output sync in the document UI: real-time collaboration in JupyterLab/Notebook.
Install
To install the extension for use in JupyterLab or Notebook 7, execute:
pip install "jupyter_server_nbmodel[lab]"
For API-only use:
pip install jupyter_server_nbmodel
Uninstall
To remove the extension, execute:
pip uninstall jupyter_server_nbmodel
Troubleshoot
If you are seeing the frontend extension, but it is not working, check that the server extension is enabled:
jupyter server extension list
If the server extension is installed and enabled, but you are not seeing the frontend extension, check the frontend extension is installed:
jupyter labextension list
Existing notebooks stop receiving live outputs
Outputs are saved by the server and never appear in the notebook: the collaborative history of that document carries updates the browser cannot integrate.
Reconciliation explains what was
found, what writes the outputs in each mode, and the outputRecovery setting that works around it.
How does it works
Generic case
Execution of a Python code snippet: print("hello")
sequenceDiagram
actor Frontend; participant Shared Document; actor Server; participant ExecutionStack; actor Kernel
Frontend->>Shared Document: [*] busy
Frontend->>+Server: POST /api/kernels/<id>/execute
Server->>+ExecutionStack: put() request into queue
ExecutionStack->>Kernel: Execute request msg
activate Kernel
ExecutionStack-->>Server: Task uid
Server-->>-Frontend: Returns task uid
loop Running
Kernel->>Server: stream / display_data / execute_result / error msg
Server->>Shared Document: Add output
Shared Document->>Frontend: Document update
end
loop While status is 202
Frontend->>+Server: GET /api/kernels/<id>/requests/<uid>
Server->>ExecutionStack: get() task result
ExecutionStack-->>Server: outputs accumulated so far
Server-->>-Frontend: Request status 202 & outputs snapshot
Frontend->>Shared Document: Reconcile missing output updates
end
Kernel-->>Server: Execution reply
Server->>Shared Document: [𝒏] idle
Server-->>ExecutionStack: execution_count, status, outputs
Shared Document->>Frontend: [𝒏] idle
deactivate Kernel
Frontend->>+Server: GET /api/kernels/<id>/requests/<uid>
Server->>ExecutionStack: get() task result
ExecutionStack-->>Server: execution_count, status, outputs
Server-->>-Frontend: Status 200 & { execution_count, status, outputs }
With input case
Execution of a Python code snippet: input("Age:")
sequenceDiagram
actor Frontend; participant Shared Document; actor Server; participant ExecutionStack; actor Kernel
Frontend->>Shared Document: [*] busy
Frontend->>+Server: POST /api/kernels/<id>/execute
Server->>+ExecutionStack: put() request into queue
ExecutionStack->>Kernel: Execute request msg
activate Kernel
ExecutionStack-->>Server: Task uid
Server-->>-Frontend: Returns task uid
loop Running
Kernel->>Server: stream / display_data / execute_result / error msg
Server->>Shared Document: Add output
Shared Document->>Frontend: Document update
end
loop While status is 202
Frontend->>+Server: GET /api/kernels/<id>/requests/<uid>
Server->>ExecutionStack: get() task result
ExecutionStack-->>Server: null
Server-->>-Frontend: Request status 202
end
Kernel->>ExecutionStack: Set pending input
Frontend->>+Server: GET /api/kernels/<id>/requests/<uid>
Server->>ExecutionStack: get() task result
ExecutionStack-->>Server: Pending input
Server-->>-Frontend: Status 300 & Pending input
Frontend->>+Server: POST /api/kernels/<id>/input
Server->>Kernel: Send input msg
Server-->>-Frontend: Returns
loop While status is 202
Frontend->>+Server: GET /api/kernels/<id>/requests/<uid>
Server->>ExecutionStack: get() task result
ExecutionStack-->>Server: null
Server-->>-Frontend: Request status 202
end
Kernel-->>Server: Execution reply
Server->>Shared Document: [𝒏] idle
Server-->>ExecutionStack: execution_count, status, outputs
Shared Document->>Frontend: [𝒏] idle
deactivate Kernel
Frontend->>+Server: GET /api/kernels/<id>/requests/<uid>
Server->>ExecutionStack: get() task result
ExecutionStack-->>Server: execution_count, status, outputs
Server-->>-Frontend: Status 200 & { execution_count, status, outputs }
The code snippet is always sent in the body of the POST /api/kernels/<id>/execute
request to avoid document model discrepancy; the document on the backend is only
eventually identical with the frontends (document updates are not instantaneous).
The ExecutionStack maintains an execution queue per kernel to ensure execution
order.
Contributing
Development install
Note: You will need NodeJS to build the extension package.
The jlpm command is JupyterLab's pinned version of
yarn that is installed with JupyterLab. You may use
yarn or npm in lieu of jlpm below.
# Clone the repo to your local environment
# Change directory to the jupyter_server_nbmodel directory
# Install package in development mode
pip install -e ".[test]"
# Link your development version of the extension with JupyterLab
jupyter labextension develop . --overwrite
# Server extension must be manually installed in develop mode
jupyter server extension enable jupyter_server_nbmodel
# Rebuild extension Typescript source after making changes
jlpm build
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.
# Watch the source directory in one terminal, automatically rebuilding when needed
jlpm watch
# Run JupyterLab in another terminal
jupyter lab --autoreload
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).
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:
jupyter lab build --minimize=False
Development uninstall
# Server extension must be manually disabled in develop mode
jupyter server extension disable jupyter_server_nbmodel
pip uninstall jupyter_server_nbmodel
In development mode, you will also need to remove the symlink created by jupyter labextension develop
command. To find its location, you can run jupyter labextension list to figure out where the labextensions
folder is located. Then you can remove the symlink named jupyter-server-nbmodel within that folder.
Testing the extension
Server tests
This extension is using Pytest for Python code testing.
Install test dependencies (needed only once):
pip install -e ".[test]"
# Each time you install the Python package, you need to restore the front-end extension link
jupyter labextension develop . --overwrite
To execute them, run:
pytest
Frontend tests
This extension is using Jest for JavaScript code testing.
To execute them, execute:
jlpm
jlpm test
Integration tests
This extension uses Playwright for the integration tests (aka user level tests). More precisely, the JupyterLab helper Galata is used to handle testing the extension in JupyterLab.
More information are provided within the ui-tests README.
Manual testing
# Terminal 1.
# You can also invoke `make jupyter-server`
jupyter server --port 8888 --autoreload --ServerApp.disable_check_xsrf=True --IdentityProvider.token= --ServerApp.port_retries=0
# Terminal 2.
KERNEL=$(curl -X POST http://localhost:8888/api/kernels)
echo $KERNEL
KERNEL_ID=$(echo $KERNEL | jq --raw-output '.id')
echo $KERNEL_ID
RESPONSE=$(curl --include http://localhost:8888/api/kernels/$KERNEL_ID/execute -d "{ \"code\": \"print('1+1')\" }")
echo $RESPONSE
RESULT_PATH=$(echo $RESPONSE | grep -oP 'Location:\s*\K[^ ]+' | tr -d '\r\n')
echo $RESULT_PATH
URL="http://localhost:8888${RESULT_PATH}"
echo $URL
curl "$URL"
# {"status": "ok", "execution_count": 1, "outputs": "[{\"output_type\": \"stream\", \"name\": \"stdout\", \"text\": \"1+1\\n\"}]"}
Running Tests
Install dependencies:
pip install -e ".[test]"
To run the python tests, use:
pytest
# To test a specific file
pytest jupyter_server_nbmodel/tests/test_handlers.py
# To run a specific test
pytest jupyter_server_nbmodel/tests/test_handlers.py -k "test_post_execute"
Development uninstall
pip uninstall jupyter_server_nbmodel
Packaging the extension
See RELEASE
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file jupyter_server_nbmodel-0.2.7.tar.gz.
File metadata
- Download URL: jupyter_server_nbmodel-0.2.7.tar.gz
- Upload date:
- Size: 279.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30667c3e3a789d7c09315981a87c0890c0352f30d6565ce2cf464043625a2e85
|
|
| MD5 |
09011c40299ec4f1db6b4009fcda05b9
|
|
| BLAKE2b-256 |
b236490ca2e29c68be0b5ce1f0787d3a6f86552f976c93dd09c5337264570bca
|
File details
Details for the file jupyter_server_nbmodel-0.2.7-py3-none-any.whl.
File metadata
- Download URL: jupyter_server_nbmodel-0.2.7-py3-none-any.whl
- Upload date:
- Size: 86.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bf473264d85e700a6fb286c03f2a73feb2c2d66f3e54f8d716f4b4eb89aab92
|
|
| MD5 |
263bb4c84217d1008c055c96d47aa3a1
|
|
| BLAKE2b-256 |
77306a4933dca5a7be39f6195db4eb5f51f909ad2f8bcb442c141bd4b25a024a
|