I'm looking for a work flow to extract specific cells from a notebook. If I can tag the cells I want to end up in the final script, how would I extract them?
I've tried nbmanips but it does not work as expected.
I'm looking for a work flow to extract specific cells from a notebook. If I can tag the cells I want to end up in the final script, how would I extract them?
I've tried nbmanips but it does not work as expected.
Figured it out
from nbmanips import Notebook
nb = Notebook.read_ipynb("scratch.ipynb")
nb.select(lambda cell: cell.metadata != {} and 'prod' in cell.metadata.tags).keep()
nb.to_py("prod.py")
little changed,and passed at jupyter notebook v6.4.11
from nbmanips import Notebook
nb = Notebook.read_ipynb("scratch.ipynb")
nb.select(lambda cell: 'tags' in cell.metadata and 'm01' in cell.metadata['tags']).keep()
nb.to_py("m01.py")
© 2022 - 2024 — McMap. All rights reserved.
nbformat
. It has the concepts of notebooks, cells, and tags baked in. See here for a related example with code and here for more a more general introduction to nbformat. I feel nbformat is more general than nbmanips as nbformat is an integrated part of the Jupyter ecosystem and thus your generated code would be more conveniently useful in more places going forward. – Benefaction