Jupyter notebook – Execute from Command Line with parameters
The best way to execute a jupyter notebook with parameters is to use Papermill
pip install papermill
- create a cell at the start of your jupyter notebook and add the tag:
- add your variables to that cell
project_key = 'some default value'
date = '2021-09-10'
- and execute the command
papermill my-jupyter-notebook.ipynb my-output-notebook.ipynb -p project_key data-science-proj-key -p date '2021-08-01'
--p – the variable name and the value to be injected
More details here: papermill@github
Jupyter notebook – Execute from Command Line
A typical command to execute a jupyter notebook from command line:
jupyter nbconvert --to notebook --execute mynotebook.ipynb --output output-name
--to notebook – the output format
--execute – the name of the notebook to be executed
--output – an optional name for the generated file
One question sometimes asked is if it is possible to pass parameters to a jupyter notebook.
- Yes, it is possible, but you need help from
papermill. See my next posts for more details.
Jupyter notebook – Export to HTML
A typical command to export a jupyter notebook to html:
jupyter nbconvert my-notebook.ipynb --to html --no-input --no-prompt --output my-notebook-html
--to html – the output format
--no-input – without the python code
--no-prompt – remove the prompts from the output
--output – an optional name for the html generated file