Jupytext 2-way reformat of Jupyter notebooks


Jupytext can save and reformat Jupyter notebooks

I was trying to test a Jupyter notebook from NCBI titled “Getting Started with NCBI Data in Python” (March 2, 2022) that is now on a “Binder” web page. However, the system kept stalling, but I was given access to the “raw” script. To my surprise the format was different than what I knew to be a Jupyter notebook (which uses a “json” format with lots of curly brakets {}.

The script I had saved had a YAML header, common in the RMarkdown world. But most line started with (hash and a space). These lines appeared to correspond to Jupyter cells containing markdown. This proved correct after convertion (below.)

It took some “google skills” to bypass lots of other web sites that were confusing.

After some search I discovered Jupytext. The best documentation is on the “pypi.org Python repository: https://pypi.org/project/jupytext/

I used the pip installation but other options are shown, including conda.

pip install jupytext --upgrade

Once installed I could convert the “strange” script into a usable notebook with the command:

jupytext --to notebook --update workshop.py 

After that I could open the notebook in Jupyter.

It is necessary to scroll down quite far on the page to find the section Command line conversion with lost of conversion options.

Image credits: Jupiter landscape from Pixabay ChristianBodhi.