# Run .ipynb programmatically

**URL:** <https://discourse.jupyter.org/t/run-ipynb-programmatically/9270>\
**Category:** JupyterLab\
**Tags:** how-to, help-wanted\
**Created:** [May 19, 2021, 11:53pm UTC](https://discourse.jupyter.org/t/run-ipynb-programmatically/9270 "2021-05-19T23:53:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rising\_star](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@rising\_star](https://discourse.jupyter.org/u/rising_star)\
**Post date:** [May 19, 2021, 11:53pm UTC](https://discourse.jupyter.org/t/run-ipynb-programmatically/9270/1 "2021-05-19T23:53:20Z")

</div>

Hi,  
We use Enterprise Gateway with Jupyterlab in our setup. There is a use case, wherein we want to run .ipynb against the jupyter server programmatically (via an api or any other way). I came across papermill doing exactly the same, but its not an jupyterlab extension and also it doesnt support Enterprise gateway.  
Whats the best way to achieve this functionality? Not sure if such a functionality can be achieved via an extension? Any help is greatly appreciated.

Thanks  
Amit

---

<div class="post-metadata">

**Author:** ![adpatter](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/adpatter/32/21229_2.png) [@adpatter](https://discourse.jupyter.org/u/adpatter)\
**Post date:** [May 20, 2021, 5:59pm UTC](https://discourse.jupyter.org/t/run-ipynb-programmatically/9270/2 "2021-05-20T17:59:42Z")

</div>

Is this a viable approach?

[https://nbconvert.readthedocs.io/en/latest/execute\_api.html#module-nbconvert.preprocessors](https://nbconvert.readthedocs.io/en/latest/execute_api.html#module-nbconvert.preprocessors)

You can write an extension that will run all the cells in a notebook. Is that what you are looking for?

Here is an example of iterating over cells and running them: [etc-jupyterlab-cell-iterate-run/index.ts at cfa483b168c04ce3f10e0b8d0f7d1ced7074048b · educational-technology-collective/etc-jupyterlab-cell-iterate-run · GitHub](https://github.com/educational-technology-collective/etc-jupyterlab-cell-iterate-run/blob/cfa483b168c04ce3f10e0b8d0f7d1ced7074048b/src/index.ts)

The functions in the NotebookActions namespace may also be relevant: [NotebookActions | @jupyterlab](https://jupyterlab.readthedocs.io/en/stable/api/modules/notebook.notebookactions.html)

---

<div class="post-metadata">

**Author:** ![rising\_star](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@rising\_star](https://discourse.jupyter.org/u/rising_star)\
**Post date:** [May 21, 2021, 4:54pm UTC](https://discourse.jupyter.org/t/run-ipynb-programmatically/9270/3 "2021-05-21T16:54:59Z")

</div>

Thanks a lot @adpatter for your reply. I looked at nbcovert, but wasnt sure how it works with enterprise gateway, but got some good leads from gitter chat, let me explore more.

---

<div class="post-metadata">

**Author:** ![nawar29](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/nawar29/32/1299_2.png) [@nawar29](https://discourse.jupyter.org/u/nawar29)\
**Post date:** [May 24, 2021, 6:06pm UTC](https://discourse.jupyter.org/t/run-ipynb-programmatically/9270/4 "2021-05-24T18:06:53Z")

</div>

Papermill  
[https://papermill.readthedocs.io/en/latest/reference/papermill-workflow.html#module-papermill.execute](https://papermill.readthedocs.io/en/latest/reference/papermill-workflow.html#module-papermill.execute)

---

<div class="post-metadata">

**Author:** ![rising\_star](https://avatars.discourse-cdn.com/v4/letter/r/df705f/32.png) [@rising\_star](https://discourse.jupyter.org/u/rising_star)\
**Post date:** [May 24, 2021, 9:10pm UTC](https://discourse.jupyter.org/t/run-ipynb-programmatically/9270/5 "2021-05-24T21:10:25Z")

</div>

I was able to run this using nbclient [here](https://github.com/jupyter/enterprise_gateway/issues/972)
