# Programmatically open new notebook

**URL:** <https://discourse.jupyter.org/t/programmatically-open-new-notebook/2636>\
**Category:** JupyterLab\
**Created:** [November 8, 2019, 1:11pm UTC](https://discourse.jupyter.org/t/programmatically-open-new-notebook/2636 "2019-11-08T13:11:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefano\_Fioravanzo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/stefano_fioravanzo/32/849_2.png) [@Stefano\_Fioravanzo](https://discourse.jupyter.org/u/Stefano_Fioravanzo)\
**Post date:** [November 8, 2019, 1:11pm UTC](https://discourse.jupyter.org/t/programmatically-open-new-notebook/2636/1 "2019-11-08T13:11:17Z")

</div>

I would love to have my JupyterLab extension detect a specific env variable at start up (like: RESUME\_NOTEBOOK) and have it open the notebook at the path specified by the env variable.

Is this achievable? Thank you!

---

<div class="post-metadata">

**Author:** ![Remborg](https://avatars.discourse-cdn.com/v4/letter/r/f14d63/32.png) [@Remborg](https://discourse.jupyter.org/u/Remborg)\
**Post date:** [November 11, 2019, 8:28am UTC](https://discourse.jupyter.org/t/programmatically-open-new-notebook/2636/2 "2019-11-11T08:28:23Z")

</div>

It is doable but you will need 2 extensions.  
A labextension (front-end) to run commands to open the notebook (using the core tokens) and a server extension (back-end) to read the env variable, receive requests from the front-end and process them (so to create, read, delete and update files).  
JupyterLab handles all of this already (through the filebrowser extension) but it’s limited to where you start it. If you want to open a notebook in this folder then you will be able to reuse JupyterLab’s api (and will only need the front-end extension).

---

<div class="post-metadata">

**Author:** ![Stefano\_Fioravanzo](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/stefano_fioravanzo/32/849_2.png) [@Stefano\_Fioravanzo](https://discourse.jupyter.org/u/Stefano_Fioravanzo)\
**Post date:** [November 11, 2019, 9:06am UTC](https://discourse.jupyter.org/t/programmatically-open-new-notebook/2636/3 "2019-11-11T09:06:04Z")

</div>

Thank you @Remborg I actually managed to do this using `IDocumentManager.openOrReveal` method to open a Notebook. To detect the env variables I am creating a new Kernel as documented [here](https://github.com/jupyterlab/jupyterlab/tree/473348d25bcb258ca2f0c127dd8fb5b193217135/packages/services) and running `os.envron.get(..)` in the Python kernel.

---

<div class="post-metadata">

**Author:** ![Sachin\_Sharma](https://yyz1.discourse-cdn.com/flex031/user_avatar/discourse.jupyter.org/sachin_sharma/32/5851_2.png) [@Sachin\_Sharma](https://discourse.jupyter.org/u/Sachin_Sharma)\
**Post date:** [January 17, 2022, 9:34am UTC](https://discourse.jupyter.org/t/programmatically-open-new-notebook/2636/4 "2022-01-17T09:34:58Z")

</div>

Hi @Stefano_Fioravanzo ,

We also have a same requirement where we are already having some notebooks file and want to open those programmatically.  
If you don’t mind, can you please share code that worked for you.

Thanks,
