Generate static HTML mirrors for notebooks in repositories
Project description
nbmirror
nbmirror builds static HTML mirror pages for Jupyter notebooks in repositories that use a simple structure:
index.htmlat repository root- notebooks under
notebooks/ - generated mirrors under
notebooks_html/
It is designed for static hosting such as GitHub Pages. It does not run a Python server, and it does not execute notebooks by default.
Why
Notebook links in static sites are awkward to maintain when you want rendered pages with rich outputs. nbmirror converts stored notebook outputs into browsable HTML pages that can be linked from your root index.html.
In the past I used nbviewer a for this purpose, but recently it very often gives 503 Error: Service Unavailable / GitHub API rate limit exceeded. Try Again Later.
Also, I prefer to have the possibility to hide the code of the notebooks, for a lean reading experience.
Expected repository layout
.
├─ index.html
├─ notebooks/
│ └─ ... .ipynb
└─ notebooks_html/
└─ ... .html (generated)
Features
- Maps notebook paths to stable mirror paths:
notebooks/eda.ipynb->notebooks_html/eda.htmlnotebooks/sales/q1.ipynb->notebooks_html/sales/q1.html
- Preserves markdown cells and stored outputs
- Keeps code hidden by default
- Adds per-cell code toggle controls with
aria-expanded - Adds Home buttons at top and bottom of each page
- Computes correct relative Home links back to root
index.html - Preserves rich outputs such as pandas HTML tables and Plotly output content
Installation
python -m venv .venv
# Windows
.venv\Scripts\activate
# macOS/Linux
# source .venv/bin/activate
pip install -e .
CLI usage
nbmirror build notebooks/nb_example.ipynb
nbmirror build-many notebooks/a.ipynb notebooks/sub/b.ipynb
nbmirror install-hook
Options (where relevant):
--repo-root(default:.)--notebooks-dir(default:notebooks)--output-dir(default:notebooks_html)--home-target(default:index.html)--verbose
Examples:
nbmirror build notebooks/sales/q1.ipynb --verbose
nbmirror build-many notebooks/a.ipynb notebooks/b.ipynb --output-dir notebooks_html
Plain Git hook installation
Install a pre-commit hook directly into .git/hooks/pre-commit:
nbmirror install-hook
Behavior:
- The hook rebuilds mirrors only for staged notebook paths.
- If generated mirror files are updated, the hook auto-stages
notebooks_html/changes and exits nonzero. - Re-run the same commit command once; the second attempt should pass with staged mirror updates included.
pre-commit framework integration
This repository ships .pre-commit-hooks.yaml with hook id nbmirror.
Example .pre-commit-config.yaml:
repos:
- repo: https://github.com/your-org/nbmirror
rev: v0.1.0
hooks:
- id: nbmirror
args: ["--repo-root", "."]
Note on generated files:
- Framework-managed hooks that modify files generally require re-stage/re-commit. That is expected.
Static hosting notes
Generated HTML pages are static files suitable for GitHub Pages and similar hosts.
Limitations and tradeoffs
- Notebooks are not executed. Only stored outputs are rendered.
- Deleted notebooks do not automatically remove stale mirror HTML files.
- Layout and toggle behavior are intentionally minimal to keep generated pages deterministic and maintainable.
Development
pytest
Project details
Release history Release notifications | RSS feed
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 nbmirror-0.1.0.tar.gz.
File metadata
- Download URL: nbmirror-0.1.0.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
131fe514852b917ebe5a54ea04a294891fc5ec3e585232d6d75b33bcbbe8b4df
|
|
| MD5 |
a364673f57535293c9efd8467b9edc8e
|
|
| BLAKE2b-256 |
8949700d78b383e20cdcedf67ba67a17a17499917a68143e9686ce2ce195a061
|
File details
Details for the file nbmirror-0.1.0-py3-none-any.whl.
File metadata
- Download URL: nbmirror-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a184ae907069e5e528c3f0cb149232d300b5dcf27d8004a931483c0bc1f8afa6
|
|
| MD5 |
c07b3dbfed5d3467c1a50d7628a17c05
|
|
| BLAKE2b-256 |
04fafd9d706cd2c17cdb91e06abd4559751ccb99c20ac2b8901b318ce8e9bef0
|