JupyterLite
JupyterLite is a browser-based version of Jupyter Notebook and JupyterLab. The official documentation can be found here.
JupyterLite provides a low-setup way of running Python, similar to Google Colab but without needing a Google account. Because JupyterLite runs entirely in a web browser, it can also be used on devices that are not normally configured for programming, including tablets, Chromebooks, and phones.
A phone is unlikely to be convenient for writing substantial amounts of code, but a purpose-built notebook can support quick calculations, data checks, and on-the-spot analysis at the laboratory bench. The usability and performance will depend on the notebook design, screen size, browser, and available device memory.
Try JupyterLite
The JupyterLite instance below opens a short, self-contained sequence-analysis notebook demonstrating Biopython, NumPy, pandas, and Matplotlib. The first run may take a little while because the packages are downloaded into the browser; later runs can reuse the browser’s cache.
jupyterlite_demo.ipynb already exists, choose Overwrite to load the latest published version. Choose Cancel to retain your locally edited copy, and download it before replacing it if you want to keep those changes.
Try JupyterLite REPL
JupyterLite also offers a REPL (Read-Eval-Print Loop), similar to what you get when you run python in a terminal. The REPL from the AU-MBG JupyterLite environment is embedded below. The examples below suggest small tasks to try in the REPL.
The REPL is a low-friction way to run code: students can begin experimenting without creating a file or navigating a notebook. It opens without any exercise content or pre-written cells. This lack of visible scaffolding can be useful when the aim is to have students write a small amount of code themselves rather than only run code that has already been provided.
A notebook can also begin with an empty cell, but the REPL invites a different kind of scaffolding. Instructions can introduce a task one small step at a time, with each expression entered and evaluated in sequence. The resulting feedback can guide the student’s next step.
Like the terminal REPL (python), it is intended primarily for temporary work. For work that must be saved, shared, or reproduced, transfer the code to a notebook or script.
The REPL can be used to gain intuition about an equation. Consider, for example,
\[ A(t) = A_0 e^{-kt} \]
Ask students what role \(A_0\) plays, and guide them through the exploration one step at a time:
- Import NumPy using the conventional abbreviation
np. - Create an array named
tcontaining the integers from 0 through 5. The functionnp.arangemay be useful here. - Assign the value 0.5 to
kand the value 2 toA0. - Translate the equation into a Python expression. NumPy provides
np.exp(...)for the exponential function. - Change
A0to 1 and then to 5, evaluating the expression after each change.
Then ask:
- What changes when \(A_0\) changes?
- Does the rate of decay change?
- Try changing \(k\) instead. How is its effect different from changing \(A_0\)?
This lets students discover that \(A_0\) determines the starting value, whereas \(k\) determines the rate of decay.
Possible solution
Authors and instructors can paste the following complete example into the REPL to try the exercise themselves:
import numpy as np
t = np.arange(0, 6)
k = 0.5
A0 = 2
A0 * np.exp(-k * t)
A0 = 1
A0 * np.exp(-k * t)
A0 = 5
A0 * np.exp(-k * t)
k = 1
A0 * np.exp(-k * t)Ask students to plot the following small sample from the relationship \(y=x^2\):
| x | y |
|---|---|
| 1 | 1 |
| 2 | 4 |
| 3 | 9 |
| 4 | 16 |
| 5 | 25 |
Before plotting, ask students to predict the value of \(y\) when \(x=6\). Then guide them through the task:
- Import
matplotlib.pyplotusing the conventional abbreviationplt. - Enter the values from each table column as lists named
xandy. - Create a figure and axes with
plt.subplots(). - Use the axes method
scatterto plotxagainsty, then display the figure withplt.show(). - Add the predicted point to both lists and make the plot again.
How much syntax to provide is itself a scaffolding choice. For beginners, a method name or partial expression may be enough to unblock the next step without supplying a complete solution to copy.
Possible solution
Authors and instructors can paste the following complete example into the REPL to try the exercise themselves:
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]
fig, ax = plt.subplots(figsize=(3, 3))
ax.scatter(x, y)
plt.show()
x.append(6)
y.append(36)
fig, ax = plt.subplots(figsize=(3, 3))
ax.scatter(x, y)
plt.show()Examples of available packages
For many tasks this is essentially a full-fledged Python notebook interface and can for example be used for tasks requiring packages such as
- Matplotlib: Core plotting library that can be used to make practically any type of scientific plot.
- NumPy: Provides efficient numerical calculations with multidimensional arrays.
- SciPy: Supplies algorithms for scientific computing, including optimization, integration, interpolation, and statistics.
- pandas: Supports the manipulation, analysis, and visualization of tabular data.
- Biopython: Provides tools for biological sequence analysis and common bioinformatics file formats.
- Pyrodigal: Predicts protein-coding genes in prokaryotic genomes and metagenomes.
- pysam: Reads and manipulates common genomics file formats such as SAM, BAM, and VCF.
- sourmash: Uses k-mers to compare genomes and analyse genomic or metagenomic datasets.
- msprime and tskit: Simulate and analyse ancestry and genetic variation in populations.
- FreeSASA: Calculates solvent-accessible surface areas for proteins and other molecular structures.
- scikit-image: Provides image-processing algorithms useful for microscopy and other biological images.
Technical details
JupyterLite provides the JupyterLab interface as a static web application. Python code is executed in the browser by the Pyodide kernel, which uses WebAssembly (WASM). This removes the need for a dedicated Jupyter server, although the static site and packages still need to be hosted.
The AU-MBG JupyterLite environment
The JupyterLite environment used on this page is maintained in the AU-MBG JupyterLite playground repository and published through GitHub Pages. Keeping the environment separate from the handbook makes it possible to reuse the same browser-based Python environment across several course-material sites while managing its JupyterLite, Pyodide, and extension versions centrally.
The deployment includes jupyterlab-open-url-parameter, which can open a notebook supplied through the fromURL query parameter. In the example above, the notebook is generated and hosted by the handbook, while the separate JupyterLite deployment provides the interface and Python runtime. The notebook is copied into the learner’s browser when it is opened, and any subsequent edits remain local unless the learner downloads the file.
Package installation
Package installation works slightly differently in JupyterLite than in a regular Python environment. In the Pyodide kernel, packages can be installed with micropip, for example:
# In the Pyodide kernel, micropip installs packages compiled for WebAssembly.
import micropip
await micropip.install(["biopython", "numpy", "pandas", "matplotlib"])After the cell has run, the packages are available in the current browser environment. The first installation may take a little while, but downloaded package files may be cached by the browser.
Package compatibility
Many pure-Python packages can be installed directly from PyPI with micropip, provided their dependencies are also compatible with Pyodide. Many widely used scientific packages that contain compiled code are available too, including NumPy, SciPy, pandas, and the biology-oriented packages listed above.
The main limitation is that binary packages built for an ordinary desktop or server cannot be used unchanged in the browser. Packages containing extensions written in languages such as C, C++, Fortran, or Rust need a Pyodide-compatible WebAssembly build, as do any compiled dependencies. Packages that rely on operating-system features such as external programs or subprocesses may also require adaptation.
For most teaching exercises this is a design constraint rather than a major obstacle: choose from the broad set of packages already built for Pyodide and test the notebook in the deployed JupyterLite environment. If an essential package is unavailable, the same exercise can instead be offered through a server-backed service or a local Python environment.
The exact package versions available depend on the Pyodide version used by the JupyterLite deployment. Consult the Pyodide package list and test imports when preparing or updating an exercise.
Some packages, particularly interactive widgets and custom output renderers, also require a compatible JupyterLab frontend extension. Installing only the Python package may therefore not provide every feature of such a package.
Browser storage and saving work
Files and notebook changes are saved locally in the browser, usually using IndexedDB. They are not automatically uploaded to GitHub or synchronized between browsers, devices, or users. Learners should download work they need to keep before clearing browser data or moving to another device.
A locally modified copy can take precedence over a newer hosted file with the same name. If an updated exercise appears not to have changed, rename or remove the older browser copy before opening the exercise again. See the JupyterLite documentation on content and browser storage for further details.
Performance and suitable workloads
JupyterLite is well suited to teaching examples, exploratory analysis, and small or moderately sized datasets. Computation uses the learner’s own device, so execution speed and available memory vary between users. Large datasets, long-running calculations, and memory-intensive analyses are usually better suited to a local Python installation or a server-backed notebook environment.
Network and system limitations
Code running in Pyodide uses the browser’s networking facilities and is subject to browser security rules such as Cross-Origin Resource Sharing (CORS). This means that an otherwise public data URL may still be inaccessible if its server does not permit requests from other websites.
Packages that rely on unrestricted network sockets, external command-line programs, subprocesses, threading, or multiprocessing may not behave as they do in a conventional Python environment. These restrictions rarely affect the small, self-contained exercises for which JupyterLite is intended, but they should be considered when adapting an existing analysis. The Pyodide compatibility documentation describes the current platform limitations.