Embed interactive notebooks in your MkDocs site using JupyterLite.
Project description
mkdocs-jupyterlite
A MkDocs plugin for embedding interactive notebooks in your docs via jupyterlite.
Say you have a notebook example.ipynb in your awesome project, and you want
users to be able to play around with it.
By using JupyterLite,
you can run Jupyter notebooks directly in the browser without any server-side dependencies.
See this project's documentation site for a live example.
Installation
Step 1: Install the plugin from PyPI:
python -m pip install mkdocs-jupyterlite
Step 2: Configure your mkdocs.yml file
See the mkdocs.yml that configures this project's site.
site_name: mkdocs-jupyterlite
site_url: https://nickcrews.github.io/mkdocs-jupyterlite/
repo_url: https://github.com/nickcrews/mkdocs-jupyterlite/
nav:
- Home: index.md
- Notebook 1: notebook.ipynb
plugins:
- jupyterlite:
enabled: true
notebook_patterns:
# include all
- "**/*.ipynb"
# exclude drafts
- "!**/draft_*.ipynb"
# re-include a specific draft
- "project/drafts/draft_keep.ipynb"
# exclude an anchored notebook
- "!/top_secret.ipynb"
wheels:
# Specify a url directly.
- url: "https://files.pythonhosted.org/packages/2d/2c/7f32ba15302847f0cd0d01101470b2f427ec5b3a07756f41c823c01c0242/ibis_framework-10.5.0-py3-none-any.whl"
# Run a shell command that dynamically
# builds/fetches/creates 0 to N .whl files in the given {wheels_dir}
# (which will be replaced by this plugin with a real, temporary directory).
- command: "curl -L -o {wheels_dir}/cowsay-6.1-py3-none-any.whl https://files.pythonhosted.org/packages/f1/13/63c0a02c44024ee16f664e0b36eefeb22d54e93531630bd99e237986f534/cowsay-6.1-py3-none-any.whl"
- command: "cd src/package_not_on_pypi/ && uv build --out-dir {wheels_dir}"
Here are the details on the configuration options:
enabled
bool, whether or not the plugin is enabled. Defaults to true.
notebook_patterns
A list of patterns that uses gitignore semantics to include and exclude files. The last matching pattern will be used to determine if a file is a notebook.
These are resolved relative to your MkDocs docs_dir directory,
which by default for most projects is docs/.
So if you have a notebook at docs/notebook.ipynb,
that corresponds to the pattern /notebook.ipynb.
For all files that match, the content of the page will be an iframe that embeds the JupyterLite Notebook html.
wheels
A list of wheels to include in the JupyterLite environment.
The simplest form is to specify a file path or URL directly underneath the url key.
Or, if you use the command key, this is interpreted as a shell command.
This plugin will replace the {wheels_dir} placeholder with a temporary directory,
and then run the command in the directory that the mkdocs command was run from.
This command must place/create 0 to N .whl files in the given {wheels_dir} directory.
Related Work and Alternatives
- Binder: A popular tool for creating sharable, interactive environments for Jupyter notebooks. Requires a full docker environment and a remote server. The notebook is hosted separately from your docs, so a user has to click away in order to run the notebook. Takes 30-60 seconds to boot up a new environment.
- mkdocs-jupyter: A MkDocs plugin that embeds static Jupyter notebooks into your MkDocs site. That project is very similar to this one, except that one executes and renders the notebooks as static HTML at build time, so they aren't interactive on the site. It is much more mature than this project though.
- jupyterlite-sphinx:
A Sphinx extension that integrates JupyterLite within your Sphinx documentation.
That project is very similar to this one, except that it is for Sphinx
instead of MkDocs.
It also has more features than this project.
I will probably use that as inspiration for future development of this project,
for example how it uses
environment.ymlto specify python packages that will be included in the JupyterLite environment. - jupyterlite: The core project that powers this plugin. You can use jupyterlite directly in your docs, it just is more work. You would need to a build step to package your notebooks, other files, and python dependencies into a single static .html file. Then you would need to inject this .html file into the proper pages of your MkDocs site. This plugin automates that process for you.
Contributing
I want this to be usable for other people, so file an issue if you want to use this in your site, but run into any problems.
Possible improvements:
- Include custom python wheels into the JupyterLite environment.
- Passing an entire jupyter-lite.json config file.
- Instead of using an iframe, actually inline the contents of the generated HTML?
- Fix the TOC so clicking headers actually scrolls in the iframe.
Project details
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 mkdocs_jupyterlite-0.3.0.tar.gz.
File metadata
- Download URL: mkdocs_jupyterlite-0.3.0.tar.gz
- Upload date:
- Size: 140.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b5f407777a4a682fbf40282b012e303da1c5cf93e427f7a84f9f4bb6a480d8ac
|
|
| MD5 |
bd74aea4bb695979fa31e5c35e0e83dc
|
|
| BLAKE2b-256 |
e9e7adb78d9d42bfd36e00eb1e2db9309928a24938efddd9694e8ff251e66793
|
Provenance
The following attestation bundles were made for mkdocs_jupyterlite-0.3.0.tar.gz:
Publisher:
publish.yml on NickCrews/mkdocs-jupyterlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_jupyterlite-0.3.0.tar.gz -
Subject digest:
b5f407777a4a682fbf40282b012e303da1c5cf93e427f7a84f9f4bb6a480d8ac - Sigstore transparency entry: 382863086
- Sigstore integration time:
-
Permalink:
NickCrews/mkdocs-jupyterlite@45dd8e5f12772a511c77b7dbc7a227e80c4621de -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/NickCrews
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@45dd8e5f12772a511c77b7dbc7a227e80c4621de -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file mkdocs_jupyterlite-0.3.0-py3-none-any.whl.
File metadata
- Download URL: mkdocs_jupyterlite-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce65f38e5f8ec5e01712da59831d0f9fa057f21258e107b21013989efb82e4d5
|
|
| MD5 |
8147c1471c81100a8a29510147481d7f
|
|
| BLAKE2b-256 |
c3212b7bc28717e9edaf4c08a0eb811bec51be82ea9b45501d73a9a91e409b8a
|
Provenance
The following attestation bundles were made for mkdocs_jupyterlite-0.3.0-py3-none-any.whl:
Publisher:
publish.yml on NickCrews/mkdocs-jupyterlite
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mkdocs_jupyterlite-0.3.0-py3-none-any.whl -
Subject digest:
ce65f38e5f8ec5e01712da59831d0f9fa057f21258e107b21013989efb82e4d5 - Sigstore transparency entry: 382863097
- Sigstore integration time:
-
Permalink:
NickCrews/mkdocs-jupyterlite@45dd8e5f12772a511c77b7dbc7a227e80c4621de -
Branch / Tag:
refs/tags/v0.3.0 - Owner: https://github.com/NickCrews
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@45dd8e5f12772a511c77b7dbc7a227e80c4621de -
Trigger Event:
workflow_dispatch
-
Statement type: