nbmerge: merge / concatenate Jupyter notebooks
pip install nbmerge
For the usage as originally specified by @fperez's gist,
nbmerge file_1.ipynb file_2.ipynb file_3.ipynb > merged.ipynb
Alternatively, nbmerge can cursively collect all files in the current
directory and below, recursively. After collection, it sorts them
lexicographically. You can use a regular expression as a file name
.ipynb_checkpoints are automatically ignored. And, you
can use the
-i option to ignore any notebook prefixed with an underscore
(think pseudo-private in python).
For example, the following command collects all notebooks in your project
that have the word
intro in the file name and saves it to a merged file
nbmerge --recursive -i -p ".*intro.*" -o _merged.ipynb
Finally, you can also instruct the script to demarcate the boundary
between each original file with the
-boundary [BOUNDARY] flag.
src_nb value in the metadata for the first cell in each original
notebook will then contain the path of the original notebook, relative to
the cwd at the point of script execution.
Read the docs: here.