0

How can the (JSON) contents of a Jupyter notebook (i.e. what would be saved in a .ipynb file) be accessed programmatically from within the notebook?

There is the option of forcing the notebook to be saved and then reading back the .ipynb file, but I prefer to not clobber the current .ipynb. Maybe there is a way of at least saving it under another path? That would not be ideal, but that would work.

Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260
  • This could be done with [ipylab](https://github.com/jtpio/ipylab) if the [`saveAs`](https://github.com/jupyterlab/jupyterlab/blob/90ff82bb9023be8d09b895d8e8eedac45f82eba7/packages/docregistry/src/context.ts#L322-L349) implementation accepted the path from user instead of always prompting for it, and the [associated command](https://github.com/jupyterlab/jupyterlab/blob/53e2b5823a943798a6438dae2efa21c875aa0f83/packages/docmanager-extension/src/index.tsx#L781-L800) was passing arguments to it from `execute()` so `execute(userPath?: string)`. – krassowski Dec 31 '21 at 18:52
  • If you are interested in making a PR to make it happen, I would be happy to help. – krassowski Dec 31 '21 at 18:53
  • Thanks. This is worth creating an answer that says that it cannot be done yet in Jupyter Lab. :) I would accept it. – Eric O. Lebigot Jan 01 '22 at 15:21
  • Well, it can be done either by contributing to core, or by creating an extension ;) – krassowski Jan 01 '22 at 15:25

1 Answers1

0

According to @krassowski in the comments to the question, accessing the JSON of a Jupyter Lab notebook from within itself is not currently doable.

Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260