JupyterLite¶
JupyterLite is JupyterLab running entirely in the browser: a static site with a Python kernel compiled to WebAssembly (Pyodide) and, with the terminal extension, a small shell called cockle. There is no server, so a workshop can be published as a plain set of files on GitHub Pages or any web host and opened with a link.
The extension runs in JupyterLite as it is. What the server extension would do, it does in the browser instead:
On a server |
In JupyterLite |
|---|---|
Platform detection |
Fixed: |
Download from a repository (archive) |
File by file from the raw files of the repository, through jsDelivr for GitHub and from the gist raw endpoint for a gist. |
Download from an archive URL |
Not available; use a repository URL. |
Collection index, catalog |
Fetched by the browser, so the host must send CORS headers, or ship the file inside the site. |
|
The terminal extension’s headless shell. |
|
The Pyodide kernel: Python without |
|
Not available; the actions report why. |
Checkpoints |
Copies of the files under |
Preflight |
Python is the kernel, with its version checked against the site’s; other tools must be commands of the shell, versions unchecked. |
Progress events |
Appended to |
Files written by actions, notebooks and progress live in the browser’s
storage for the site, so they survive a reload but stay on that machine.
The kernel and the terminals do not: a reload is a new instance, exactly
as a restarted server is, so a workshop with progress that is not marked
resumable asks whether to restart or continue when it is reopened;
see Progress events. A Lite
workshop that keeps nothing live between pages sets resumable: true.
The flag says the workshop does not need the kernel to have survived,
not that it never does: a workshop whose pages share one notebook’s
kernel, with later pages using what earlier pages defined, leaves it
unset, since a reload would continue it into an empty kernel.
Writing for JupyterLite¶
JupyterLite is a frontend, not an operating system: list it in the
manifest’s frontends and run jupyter workshop lint --frontend jupyterlite. A manifest that lists no frontends is written for
JupyterLab alone, so supporting JupyterLite is an explicit choice:
platforms: [linux, macos, windows]
frontends: [jupyterlab, jupyterlite]
Three rules cover the differences:
lite-shell-syntaxwarns when a command applicable to Lite uses what cockle lacks: chaining with&&or||,$VARexpansion, command substitution, or2>&1. Pipes,;and redirections work. Give the action a:jupyterlite:variant, or an empty one when there is nothing to do.lite-unsupportedwarns aboutscriptverifies and Python bodies that start processes. Hide them with:when: frontend != "jupyterlite"or give them a variant.unsupported-frontendwarns about an action a listed frontend cannot run at all,environment-createin JupyterLite, unless awhencondition or an empty variant already excludes it there.
The shell has the coreutils commands (ls, cat, echo, env,
mkdir, sed, grep, expr and so on), cd, export and a few other
builtins, but no python, git or package managers. Variables reach the
terminal through export rather than a sourced file. A requires.tools
list naming anything but Python shows the preflight banner in Lite and
puts the names in missing_tools; a tool that JupyterLite could never
provide is better declared with frontends: [jupyterlab], so it is not
looked for there.
The frontend built-in variable is jupyterlite and platform is
emscripten, Pyodide’s name for itself, so a :linux: variant is never
chosen there. Prose can adapt with ```{when} frontend == "jupyterlite"
blocks, and :when: frontend != "jupyterlite" hides an action.
A site built by jupyter workshop lite ships its workshops prebuilt,
so the collection it carries has nothing left to install and the
browser’s “Install all” has nothing to offer there; the site builder is
where a collection is bundled. Installing still works in JupyterLite,
one workshop or a whole collection, for a collection whose workshops
are not all in the site: each is downloaded file by file from its
repository, as the table above says, which takes longer than a server
unpacking an archive.
A file-by-file download cannot list a repository, so it fetches the
manifest, the pages, and the files the pages name with from,
script, or the path of file-open and notebook-open; other files,
such as starter files under files/, are not downloaded. A gist
published by jupyter workshop gist lists every file in its
workshop-tree.json, so it arrives complete, each file put back at its
path; see A workshop in a gist.
Building a site¶
jupyter workshop lite builds a static site carrying one or more
workshops, with the extension, the Pyodide kernel and the terminal, that
any web host can serve; Publishing workshops
covers the command, what the build needs, and deploying to GitHub Pages.
A site with one workshop opens it on start, and a site with several
starts in the workshop browser. The build can also carry a collection
index, a catalog, a welcome message and a settings file, such as an
analytics block, so that the site’s own address is all a link to it
needs.
Testing¶
jupyter workshop test my-workshop --frontend jupyterlite (or
--lite) builds a site with the workshop, serves it from a static file
server under a sub-path, opens it
in a headless browser and runs every action, exactly as the server
self-test does. The first run downloads the terminal’s WebAssembly
packages into the build directory; Pyodide loads from the CDN on every
run. just selftest-lite runs it on the example.
The terminal’s build step needs node, npm and micromamba on the
path. A workshop that has nothing to run in a shell is tested on a site
built without the terminal, so it needs none of them: one that does not
declare the terminal capability and has no execute-capture action
or shell check, both of which use the terminal extension’s shell
without showing a terminal.