Create a JupyterLite archive that can be used offline#
It is possible to create a fully self-contained JupyterLite archive with no request to external services.
Configure the Pyodide kernel#
By default the Pyodide files are fetched from a CDN.
The full Pyodide distribution can be pretty heavy (~180MB), but it’s possible to self-host it.
Use the --pyodide
flag to specify the Pyodide distribution you would like to use. For
example:
jupyter lite build --pyodide https://github.com/pyodide/pyodide/releases/download/0.22.1/pyodide-0.22.1.tar.bz2
Warning
Generally, a version of pyodide_kernel
is likely only compatible with variants of the
same x.y.z
version against which the release was tested, as both python
and JS APIs are still changing frequently on both sides of the dependency.
Configure the piplite wheels#
By default calling %pip install
or piplite.install()
downloads and installs packages
from the public PyPI.
Instead you can configure a list of packages that will be downloaded at build time so they can be hosted alongside your JupyterLite website.
See Ship additional Pyodide wheels at build time for more information.
Concretely that means populating a list of URLs for downloading wheels. A good example for this is the configuration used for the JupyterLite demo website: jupyter_lite_config.json
The relevant part of jupyter_lite_config.json
is the piplite_urls
list which looks
like the following:
{
"PipliteAddon": {
"piplite_urls": [
"https://files.pythonhosted.org/packages/e6/0b/24795939622d60f4b453aa7040f23c6a6f8b44c7c026c3b42d9842e6cc31/fastjsonschema-2.15.3-py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/a/asttokens/asttokens-2.0.5-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/b/backcall/backcall-0.2.0-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/b/bqplot/bqplot-0.12.33-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/c/certifi/certifi-2021.10.8-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/d/defusedxml/defusedxml-0.7.1-py2.py3-none-any.whl",
"https://files.pythonhosted.org/packages/py2.py3/e/executing/executing-0.8.3-py2.py3-none-any.whl",
"..."
]
}
}
Tweak this list based on the packages you would like to serve statically.
Offline Progressive Web App (PWA)#
JupyterLite can be used as a Progressive Web App (PWA) on mobile devices, but also on desktop.
When JupyterLite is configured to work offline as detailed in this guide, it should be possible to use JupyterLite as a PWA without any network connection. There might still be a need for using the app while still connected to the Internet first, so the underlying Service Worker can cache the assets.
Check out the Using guide for more details on how to install JupyterLite as an application.
Reference#
Check out the CLI Reference for more details.