Example - Executing a notebook from python

How to add a parameter tag

If you wanted to add your own parameter tag, you would go to the menu: View ➡️ Cell Toolbar ➡️ Tags

Input notebook

Let's take a look at the input notebook (simple_input.ipynb). This notebook has cells containing tags for the parameters.

See input notebook

Execute using the Python

We are going to use papermill's python interface to execute the notebook

The command takes the form:

pm.execute_notebook(input, output, parameters={param_name: param_value}


In [11]:
import os
import papermill as pm

binder_dir = '..'


---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
<ipython-input-11-9365d48b7dea> in <module>
      4 binder_dir2 = '..'
      5 
----> 6 raise Exception(os.path.abspath(''))

Exception: /home/mseal/Workspace/papermill/binder/cli-simple

In [ ]:
result = pm.execute_notebook(
    os.path.join(binder_dir, 'cli-simple', 'simple_input.ipynb'),
    os.path.join(binder_dir, 'cli-simple', 'simple_output.ipynb'),
    parameters={'msg': 'Hello'}
)