Jupyter notebooks are powerful and interactive documents for writing iterative python codes, but quite often their size becomes bloated. I personally find editing and debugging scripts more convenient than going through each separate cell in the notebook.
Jupytext has solved this conundrum for me. The tool lets you convert an existing Jupyter notebook to a script or a markdown document which can be used for editing (and sharing) the code file! For instance, if you wish to debug any python code in Jupyter using a script, you can simply save the notebook in the desirable format (.jl, .py or .R) and edit the code.
In order to preserve the output while editing the script or markdown document, you can use paired notebooks. With paired notebooks, along with the script or markdown document, the notebook is saved as a ‘.ipynb’ file. You can edit the text file outside the notebook and on reloading the notebook, inputs are taken from the text file. How cool is that?
Check out the below demo presented by the team where they fix the order of plot legends in a python script (on the right window). The changes can be seen in the notebook (on the left side of the GIF).
You can install Jupytext right now and get started with it by following the below steps:
1. Install jupytext
pip install jupytext --upgrade
2. Configure Jupyter to use Jupytext:
jupyter notebook --generate-config
.jupyter/jupyter_notebook_config.py
c.NotebookApp.contents_manager_class = "jupytext.TextFileContentsManager"
3. Restart jupyter for the changes to take effect:
jupyter notebook
For more details on Jupytext, you can have a look at the official Github page.
I’m sure I’m not the only one who finds editing codes in scripts more convenient. Jupytext is going to make proramming work easier and definitely save a ton of time. What I like most about Jupytext is undoubtedly the paired notebook. I can’t believe it wasn’t there before! It makes for really neat and useful watching as my script edits reflect in the notebook in real-time.
Let me know if you try this out or if you have any questions on the tool.
Lorem ipsum dolor sit amet, consectetur adipiscing elit,