Architecture
Ganymede replaces one part of the Jupyter stack: the server in the middle, between the frontends people use and the kernels that run their code. The interfaces on both sides of that server stay as they are, so the frontends and kernels on either side don't change. This page shows the Jupyter architecture first, then where Ganymede sits in it, then how Ganymede is built inside.
The Jupyter architecture
Jupyter is three layers joined by two protocols.
- Frontends show notebooks and send code to run: JupyterLab and Notebook 7 in a browser, the VS Code Jupyter extension, and other clients. They never talk to a kernel directly.
jupyter_serveris the process in the middle. It serves a REST API for kernels, sessions (which notebook uses which kernel), contents (files and checkpoints), and kernelspecs, and a websocket per kernel that carries protocol messages between frontends and the kernel. It handles auth, and serves the frontend's static files when the frontend is a web page.- Kernels run code in one language. Each is a separate process, launched from a kernelspec: a
kernel.jsonfile in a Jupyter data directory that gives the command line, display name, language, and interrupt mode. ipykernel is the Python kernel; cdp-kernel, IRkernel, and many others exist.
The two protocols are what make the layers replaceable:
- Between frontend and server, HTTP and websockets: the
jupyter_serverREST API, and two websocket framings of protocol messages (JSON, and the binaryv1.kernel.websocket.jupyter.org). - Between server and kernel, the Jupyter messaging protocol over ZeroMQ: five sockets per kernel (shell for requests, iopub for outputs and status broadcast to every client, stdin for
input(), control for interrupt and shutdown, heartbeat for liveness), each message signed with HMAC using a key from the kernel's connection file.
Inside jupyter_server, the work is split across Python packages: jupyter_client finds kernelspecs, launches kernels, and owns their sockets; nbformat reads, validates, and writes notebook files; traitlets carries configuration; and server extensions plug in more endpoints. nbclient (jupyter execute) runs notebooks headless on the same jupyter_client, without the server.
Nothing in the protocols requires Python. The server is where Python comes in: to run any notebook, even a TypeScript one, you install a Python environment for jupyter_server and jupyter_client.
Where Ganymede sits
Ganymede takes the middle box's place and keeps both of its interfaces:
- Upward, it serves the
jupyter_serverREST and websocket API, so JupyterLab and VS Code connect to it unchanged. That API is a compatibility target: where Ganymede andjupyter_serverdiffer, the difference is a bug. UIs of Ganymede's own (a TypeScript web UI, or a Swift shell with a web view on iPadOS and macOS) are clients of the same API, outside the core. - Downward, it launches kernels from the same kernelspecs in the same data directories, and speaks the same messaging protocol over ZeroMQ. A kernel can't tell Ganymede from
jupyter_server.
What changes is everything inside the box. It is Rust, one binary or one library, with no Python environment behind it. Python is still welcome as a kernel: install ipykernel and its kernelspec, and Ganymede runs it like any other.
The headless executor moves inside too. ganymede execute produces the notebook jupyter execute would, from the same library the server is built on.
| Jupyter | Ganymede | Notes |
|---|---|---|
| Messaging protocol, wire format | ganymede-protocol | Unknown content fields pass through, so kernel extras reach clients. |
jupyter_client | ganymede-kernel-host | Kernelspecs, launch, the startup handshake, interrupt, shutdown, heartbeat. |
nbformat | ganymede-nbformat | The writer's output is byte-identical to Python's, so saves don't produce diffs. |
nbclient | ganymede-exec | The same outputs, display_id updates, timings, and error handling. |
| Contents manager | ganymede-contents | Atomic writes, modification-time conflict checks, checkpoints. |
| Kernel and session managers | ganymede-api | Independent of HTTP, so an in-app bridge can call it too. |
| tornado handlers, auth | ganymede-server | axum routes, token auth, origin checks, both websocket framings, JupyterLab's page and /lab/api/*. |
jupyter CLI | ganymede | kernelspec, run, console, execute, kernel, trust, serve, lab; see CLI and configuration. |
| traitlets config | TOML config file | One file plus command-line flags. |
| Server extensions | none | Not compatible by design: they are Python. |
Inside Ganymede
The crates are layered so that each profile takes only what it needs. Lower crates know nothing of the ones above them, and the three at the bottom do no I/O, so they build for any target.
| Crate | What it is |
|---|---|
ganymede-cli | The ganymede binary. |
ganymede-ffi | A C ABI (include/ganymede.h) that runs the server on loopback inside an app and returns its URL. A static library; scripts/build-xcframework.sh packages it for the Mac, iPad and iPhone app. See Embedding. |
ganymede-server | The HTTP and websocket server. |
ganymede-engine | The library to embed: find kernelspecs, start or attach to kernels, execute with streaming output, run notebooks. See Embedding. |
ganymede-api | Kernel and session managers, response models, the per-client bridge, idle culling. No HTTP. Contents path validation confines kernel working directories to the root. |
ganymede-gateway | Kernels on another Jupyter server, as jupyter_server's gateway client: kernelspecs and lifecycle over its REST API, channels over its websocket. The server uses it for gateway_url. Its mount module forwards an allowlist of routes to another Ganymede server, for connected machines (see Connected machines). |
ganymede-terminals | Terminals for /api/terminals: the user's shell in a pseudo-terminal (portable-pty), shared by any number of clients. None on iOS or wasm. |
ganymede-lsp | Language servers for /lsp/*: the servers listed in the config file, one process each, started for the first client and shared by every client: notifications go to all, each response to the client that asked. None on iOS or wasm. |
ganymede-host | The host API comm driver (ganymede.host.v1): opens a comm over a kernel subshell, routes cell calls to a Responder, and filters host traffic from other clients. See A host API for kernels. |
ganymede-exec | Runs a notebook with nbclient's semantics. |
ganymede-contents | The contents model over a filesystem (FsContents) and multi-root named mounts (MultiRootContents). |
ganymede-documents | Document rooms: a notebook as a yrs (Yjs) document in JupyterLab's collaboration schema, and the y-websocket protocol, as a state machine with no I/O. The server hosts rooms behind /api/collaboration. |
ganymede-kernel-host | Kernelspec discovery; the KernelTransport seam (ZeroMQ, in-process); provisioners (subprocess, attach to a running kernel, registered in-app and provider kernels); the per-kernel session state machine. |
ganymede-protocol | Message types, the ZeroMQ multipart frame layout with HMAC, connection files, the websocket codecs. |
ganymede-nbformat | nbformat 4.5 reading and writing. |
Outside the Rust core, and outside this repository, Ganymede's own UI lives in tlockney/ganymede-ui: a web app that is a client of this server's API, and the Mac, iPad and iPhone app around it. How they are built is on ganymede-ui's architecture page.
Seams
Each seam is a Rust trait that the server, the engine, or an app embedding them can fill differently.
| Seam | What it abstracts | Built | Not built |
|---|---|---|---|
KernelTransport | A stream of channel messages to and from one kernel | ZeroMQ; an in-process channel (fake and registered in-app kernels); a kernel provider Unix socket; a websocket to a gateway | |
Provisioner | How a kernel comes to exist | A subprocess from a kernelspec; attaching to a running kernel's connection file; registered in-app and provider kernels (RegisteredKernels); a remote kernel through a gateway | |
TransportFactory | How a launched kernel gets its transport | ZeroMQ from its connection info; registered in-app and provider kernels (RegisteredKernels, where LaunchedKernel.connection is None); the gateway's websocket | |
KernelspecSource | Which kernels can be launched | The Jupyter data dirs plus --kernelspec-root, which is how conda and venv kernels are found without the host knowing what a venv is; a fixed list (StaticKernelspecs); registered in-app and provider kernels; a gateway's list | An environment scanner, as VS Code has |
Contents | Files, directories, checkpoints | The local filesystem (FsContents), with atomic writes and mtime and hash checks; a virtual multi-root router over named folders (MultiRootContents); on the iPad, any folder the app can open | Passing through to a remote host |
| Auth | Who may call the API | A token, traded for a login cookie; listed tailnet logins behind tailscale serve, or logins and tags from tailscale whois on the tailnet address | OIDC or a JupyterHub contract |
| Document | The live notebook model | The file, read and written per request; or a document room, a yrs document that reloads and merges changes made on disk (Live editing and document rooms) | Rooms for files other than notebooks |
The server uses kernelspec dirs, subprocesses and ZMQ unless an app embedding it passes its own KernelspecSource, Provisioner and TransportFactory in serve::Startup; its subprocess and zmq features can then be turned off.
Where the ecosystem already has a seam, Ganymede matches it rather than inventing one. Remote kernels use the protocol of jupyter_server's gateway client. ganymede-ui reaches every backend through @jupyterlab/services' ServiceManager, the seam JupyterLite uses for its in-browser server; its own seams are on its architecture page. The apps were first planned around a message bridge in place of HTTP. Running the ordinary server on loopback inside the app, through ganymede-ffi, turned out simpler, so the web view connects as a browser would.
One rule: the host knows no language
Every language-specific fact comes from the kernel: its kernelspec (language, metadata), its kernel_info_reply (language_info, extra fields), and the MIME types on its outputs. No code in the host crates depends on a kernel's language; outside tests, python appears there only where Python's output defines a file format (nbformat's float layout, the trust signature), in PyPI's names (where ganymede lab install gets JupyterLab), and in comments. The test suite runs the same scenarios against cdp-kernel and ipykernel, and both must pass.
Running a cell
Inside Ganymede, ganymede-server decodes the websocket frame, ganymede-api notes the client's session so replies find their way back, and ganymede-kernel-host sends the message on the kernel's shell socket. Every client of the kernel sees iopub, which is how a second tab shows the same outputs. Only the client that asked gets the reply. The request is complete when the reply and the matching idle have both arrived; they come on different sockets, in either order.
If the cell calls input(), the kernel sends an input_request on stdin to the client that ran the cell, which answers with an input_reply.
Kernel lifecycle
- Start. The host allocates ports, writes a connection file, and launches the kernelspec's command. It then sends
kernel_info_requeston shell and control until both answer and iopub has delivered a message. This handshake exists because ZeroMQ's PUB/SUB drops messages published before the subscriber connects. A kernel with an XPUB iopub socket (ipykernel 7, JEP 65) sendsiopub_welcomewhen the subscription arrives, which counts as that message, so one request on each channel is enough. The welcome is not passed on to clients. - Interrupt. A signal to the process group, or an
interrupt_requeston control, whichever the kernelspec'sinterrupt_modesays. - Restart and shutdown.
shutdown_requeston control, a grace period, then the process is killed. Restart launches the same kernelspec again under the same kernel id. - Crash. A kernel that exits with nothing asking it to is restarted under the same id, as
jupyter_server's restarter does; afterkernel_restart_limitcrashes in a row it is left dead (Kernel crashes). - Idle culling. With
--cull-idle-secs, kernels idle that long with no clients are shut down.
Saving a notebook
A save is one PUT /api/contents request with the whole notebook. A client that sends the ETag it read (as If-Match) or the last_modified it was given gets 412 or 409, and nothing is written, when the file changed on disk since; that is how an edit from another device isn't overwritten. Otherwise the file is replaced atomically, so a sync or a crash never sees half a notebook, and signed when every code cell is trusted.
Where it runs
The same crates, in four setups:
- Workstation or server.
ganymede serveorganymede labas a process: kernel processes over ZeroMQ, files on disk, token auth. Any Jupyter frontend connects.--gateway-urlsends kernels to another server instead. - Mac app. The server runs inside the app through
ganymede-ffiand serves ganymede-ui to aWKWebViewon loopback; when the background server LaunchAgent is enabled (ganymede-ui 0.19.0), local notebooks route through the bundledganymede serveinstead, with the in-app TypeScript kernel registered over the kernel provider Unix socket. Kernels are the Mac's kernelspecs, cdp-kernel in a hidden web view registered with the server, or a kernel server set in the app. - iPad app. The same app built for iOS, which doesn't let an app launch processes. Ganymede serves notebooks from a folder the app can open; cdp-kernel runs in a Worker in a hidden web view, registered with the server as one of its kernels, or kernels come from a kernel server through the gateway.
- Any browser, no server. ganymede-ui alone, with notebooks in IndexedDB and kernels in Workers. Ganymede isn't involved.
Python appears in none of them except as a kernelspec someone installed.
NOTE
Unreleased in ganymede-ui. A build of ganymede-ui's main adds a Pyodide Python kernel (python) to the apps' in-app kernels, registered beside cdp-kernel in-process and over its own kernel provider connection, and to the in-page kernels of "Any browser, no server" (ganymede-ui#292). Not in its latest release.
Ganymede's app covers the last three from a user's side. The in-app TypeScript kernel stays on the web view's Worker (jitless V8 was measured and not adopted; see the roadmap).
Fitting the Jupyter ecosystem
In order of value per unit of work:
- Kernel compatibility. Protocol 5.x over ZMQ plus the kernelspec convention. Every existing kernel works: cdp-kernel, ipykernel, IRkernel, IJulia, evcxr, Deno, xeus. This is the core and is non-negotiable.
- File compatibility. nbformat 4.5 with faithful round-trip. Notebooks interchange with git, GitHub rendering, nbviewer, nbconvert run elsewhere, and every other client. Core.
- Tooling conventions. Jupyter data dirs, runtime dir and connection file naming,
JUPYTER_*environment variables. Cheap, and it meansjupyter console --existing, kernel installers, and environment tools all keep working around the host. - Client compatibility. The
jupyter_serverREST API and websocket subprotocols. JupyterLab, VS Code, and other API clients connect (Other Jupyter clients has which); Notebook 7's pages aren't served. Medium cost; server and desktop profiles only. - Output and widget compatibility. The standard MIME types, comms, the
jupyter.widgetprotocol. anywidget-only is small; full ipywidgets is a dependency on the standard JS manager, taken only in profiles that expect Python kernels. - Debugger. DAP over the control channel, a DAP client in the UI. cdp-kernel and ipykernel both support it.
- Extensions. Prebuilt JupyterLab frontend extensions load as they do in JupyterLab. Server extensions, which are Python, are not compatible, by design.
Items 1 to 3 are what make "might also run Python" free: a Python kernel is just another kernelspec, and ipywidgets is just another widget manager module.
Tested versions
"Compatible" means compatible with these versions, which CI pins in ci.yml and bumps in one pull request. A weekly scheduled run repeats the end-to-end jobs with the latest release of each, so a new upstream version that breaks something shows up within a week.
| Target | Tested against | Rule |
|---|---|---|
jupyter_server REST and websocket API | jupyter_server 2.21.1, run side by side in the e2e suite | A difference is a bug. |
| Kernel protocol | 5.x; Ganymede's own messages say 5.5. ipykernel 7.4.0 and cdp-kernel 0.17.0 in the e2e suite | A difference is a bug. |
| nbformat | 4.5, against Python's nbformat through jupyter execute (nbclient 0.11.0) | Byte-for-byte saves. Version 3 is upgraded on read. |
| JupyterLab | 4.6.6, the ganymede lab install default, driven in Chromium | Other 4.x releases should work and are not tested. |
| VS Code Jupyter extension | Its remote-server requests, replayed with @jupyterlab/services 7.5 | VS Code itself is not run in CI. |
A difference from these that isn't listed in Known gaps is a bug; please report it.
Further reading
- Replacing Python: each place the reference stack assumes Python, and what Ganymede does instead.
- Live editing and document rooms: how rooms keep a live notebook and its file in step.
- Protocol and kernel host: what each component has to get right, and what is usually missed.
- User interfaces: what any notebook UI needs, and the UI options.
- Ganymede's app: ganymede-ui in a browser and on the Mac and iPad.
- Development log: findings from each step, including what JupyterLab and VS Code call and what broke.