This tool splits a Jupyter Notebook into Sub-Notebooks depending on cell metadata. It converts a Master Notebook into a Teacher Notebook and a Student Notebook; or into a Slides Notebook, a Tasks Notebook, and a Solutions Notebook.
Although the Notebook Splitter is only a single file it can be installed via pip
pip install notebook-splitterTL;DR: See notebook-splitter --help.
-
Add cell metadata to your Jupyter Notebook: Add an
exercisekey (default, can be changed) to the metadata (JSON); give it values (tags) on which to create Sub-Notebooks{ "exercise": "task" } // another cell { "exercise": "solution" } -
Use
--keepand--removeflags of the Notebook Splitter to keep and remove cells with according tags; export it to the respective Notebook:notebook-splitter input.ipynb --keep task --remove solution -o tasks.ipynb notebook-splitter input.ipynb --keep solution --remove task -o solutions.ipynb notebook-splitter input.ipynb --remove task --remove solution -o slides.ipynb
See the examples directory in this repository.
- Repeated Parameters:
--keepand--removeparameters on the command line of the script can be given multiple times:--keep task --keep onlytask --remove solution - Remove All: As a special parameter value,
--remove allwill remove all cells except those for which a--keepvalue is specified (--keep allis the default) - Stdin/Stdout: If no output file is given with
-o/--output, the resulting Notebook will be printed tostdout; if no input file as a parameter is given, the input Notebook will be read fromstdin(good for Linux-like daisy-chaining of tools) - Change Basekey: In the above example, the cell meta data key of discrimination is
exercisewhich is the default. With--basekey, this can be changed.
The values to the --keep and --remove parameters create sets of values to keep and remove. One could implement this tool probably quite cleverly with set operations (with the added complication of the --remove all ). If you can, feel free to file a merge request!