Learn everything about Analytics

Jupytext lets you use Jupyter Notebooks as Julia, Python and R Scripts or Markdown documents!

Overview

  • Jupytext allows you to save and read Jupyter notebooks in customizable formats
  • The Jupyter notebooks can be converted to scripts (Juila, Python and R) and markdown documents (python and R)
  • The developers have provided a cool demo of editing text representation outside Jupyter (video below)

 

Introduction

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:

  • Generate a Jupyter config, if you don’t have one yet:
jupyter notebook --generate-config
  • Edit:
.jupyter/jupyter_notebook_config.py
  • And append the following:
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.

 

Our take on this

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.

 

Subscribe to AVBytes here to get regular data science, machine learning and AI updates in your inbox!

 

You can also read this article on Analytics Vidhya's Android APP Get it on Google Play
Join 100000+ Data Scientists in our Community

Receive awesome tips, guides, infographics and become expert at:




 P.S. We only publish awesome content. We will never share your information with anyone.

Join 100000+ Data Scientists in our Community

Receive awesome tips, guides, infographics and become expert at:




 P.S. We only publish awesome content. We will never share your information with anyone.