Introducing Jupytext: Jupyter notebooks as Markdown documents, Julia, Python or R scripts

2 min read

Project Jupyter released Jupytext, last week, a new project which allows you to convert Jupyter notebooks to and from Julia, Python or R scripts (extensions .jl, .py and .R), markdown documents (extension .md), or R Markdown documents (extension .Rmd). It comes with features such as writing notebooks as plain text, paired notebooks, command line conversion, and round-trip conversion.

It is available from within Jupyter. It allows you to work as you would usually do on your notebook in Jupyter, and save and read it in the formats you select.

Let’s have a look at its major features. 

Writing notebooks as plain text

Jupytext allows plain scripts that you can draft and test in your favorite IDE and open naturally as notebooks in Jupyter. You can run the notebook in Jupyter for generating output, associating a .ipynb representation, along with saving and sharing your research.

Paired Notebooks

Paired notebooks let you store a .ipynb file alongside the text-only version. Paired notebooks can be enabled by adding a jupytext_formats entry to the notebook metadata with Edit/Edit Notebook Metadata in Jupyter’s menu.

On saving the notebook, both the Jupyter notebook and the python scripts are updated.

Command line conversion

There’s a jupytext script present for command line conversion between the various notebook extensions:

jupytext notebook.ipynb –to md –test      (Test round-trip conversion)

jupytext notebook.ipynb –to md –output      (display the markdown version on screen)

jupytext notebook.ipynb –to markdown           (create a file)

jupytext notebook.ipynb –to python               (create a file)

jupytext –to notebook              (overwrite notebook.ipynb) (remove outputs)

Round-trip conversion

Round-trip conversion is also possible with Jupytext. Converting Script to Jupyter notebook to script again is identity, meaning that on associating a Jupyter kernel with your notebook, the information will go to a yaml header at the top of your script. Converting Markdown to Jupyter notebook to Markdown is again identity.

Converting Jupyter to script, then back to Jupyter preserves source and metadata.

Similarly, converting Jupyter to Markdown, and Jupyter again preserves source and metadata (cell metadata available only for R Markdown).

For more information on, check out the official release notes.

Read Next

10 reasons why data scientists love Jupyter notebooks

Is JupyterLab all set to phase out Jupyter Notebooks?

How everyone at Netflix uses Jupyter notebooks from data scientists, machine learning engineers, to data analysts