How to Execute a Notebook Within a Notebook: Is It Possible and How?

14 Replies, 903 Views

Hey! So, I’ve actually done this before using `nbconvert`. You can execute a notebook within a notebook by running something like this:

```python
import nbformat
from nbconvert.preprocessors import ExecutePreprocessor

with open('notebook_to_run.ipynb') as f:
nb = nbformat.read(f, as_version=4)

ep = ExecutePreprocessor(timeout=600, kernel_name='python3')
ep.preprocess(nb, {'metadata': {'path': './'}})
```

This will execute the notebook and save the results. It’s pretty handy for automating workflows. You might wanna check out the official `nbconvert` docs for more details.

Also, if you’re into automation, `papermill` is another solid option. It’s designed for parameterizing and running notebooks, so it might fit your use case better.

Hope this helps!

Messages In This Thread



Users browsing this thread: 1 Guest(s)