Skip to content

Instantly share code, notes, and snippets.

@bollwyvl
Last active January 6, 2026 16:25
Show Gist options
  • Select an option

  • Save bollwyvl/6b3cb4c46b1764c6d9ae1e5831f86d7a to your computer and use it in GitHub Desktop.

Select an option

Save bollwyvl/6b3cb4c46b1764c6d9ae1e5831f86d7a to your computer and use it in GitHub Desktop.
nbconvert in jupyterlite
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@hgustafsson
Copy link

hgustafsson commented Dec 9, 2025

Thank you for writing these notes!
Based on your research I was able to write an updated (i.e. working on the latest Jupyterlite) and more concise example from scratch using piplite's add_mock_package and without any changes to source files or any copying of templates (which wasn't needed at least in this Jupyterlite version).
Hopefully this will make it easier to implement it as a new custom JupyterLite exporter addon, but I don't know how to create one.

The code (added below) was tested on Jupyterlite 0.7.1 at https://jupyterlite.readthedocs.io/en/stable/_static/lab/index.html

INPUT = "python.ipynb"
OUTPUT = "python.html"

import piplite
piplite.piplite.micropip.add_mock_package("nbclient", "0.10.2", modules = 
      {"nbclient": "",
       "nbclient.exceptions": "def CellExecutionError(): pass"
      })
piplite.piplite.micropip.add_mock_package("fakenbconvert", "0.0.0", modules = 
      {"nbconvert.preprocessors.execute": "def ExecutePreprocessor(*args): return args"
      })
await piplite.install(["nbconvert", "bleach", "tinycss2", "bs4"])

from nbconvert.exporters import HTMLExporter
exporter = HTMLExporter()
(html, res) = exporter.from_filename(INPUT)

from pathlib import Path
Path(OUTPUT).write_text(html)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment