0

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.

Jonathan
  • 10,792
  • 5
  • 65
  • 85
  • Related point for anyone, you can really fine-tune programmatic selections using `nbformat`. It has the concepts of notebooks, cells, and tags baked in. See [here](https://discourse.jupyter.org/t/extract-specific-cells-from-students-notebooks/7951/7?u=fomightez) for a related example with code and [here](https://stackoverflow.com/a/71244733/8508004) 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. – Wayne Apr 24 '23 at 15:31

1 Answers1

0

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")
Jonathan
  • 10,792
  • 5
  • 65
  • 85