FAST AND EFFICIENT CODING

Jupyter Extensions and tools to make life easier.

Pritish Jadhav
Geek Culture
Published in
4 min readOct 11, 2022

--

Northern Lights by Meraki Hues

If Data is the new Oil, Python is the new Refinery.

If you work with data, you have probably heard of Jupyter notebooks. Jupyter is a web-based interactive computing platform that supports over 40 programming languages including Python. I personally use Jupyter notebooks for prototyping and running ad-hoc python tasks. In this blog, I want to go over some Jupyter extensions I use daily to make my life easier and more efficient.

Ploomber: Open the .py files as notebooks

One of the most significant drawbacks of working with Jupyter notebooks is that the raw .ipynb file is illegible. Peer reviewing and version controlling (git, Phabricator, etc) Jupyter notebooks is a nightmare.

Before you burst into flames with frustration, let me introduce Ploomber — a framework that eliminates the notebook refactoring problem by allowing you to work with native.py files in the Jupyter ecosystem. You can develop code in a python file and open it as a Jupyter notebook with a single click.

https://docs.ploomber.io/en/latest/

Ploomber can be easily installed using pip:

pip install ploomber

OR conda :

conda install ploomber -c conda forge

Bonus: Ploomber is a far more powerful framework that solves various use cases that aid in developing scalable data products.

Black: Auto Format Jupyter cells:

Jupyter notebooks are known for hacking together quick and dirty solutions but that doesn't mean the code has to be unreadable. nb-black is a Jupyter extension that beautifies Python code automatically using Black. It works seamlessly with Jupyter notebook as well as JupyterLab.

The extension can be installed using the following pip command:

pip install nb_black

For auto-formatting the notebook cells, the extension needs to be loaded using the following command —

Jupyter notebook: %load_ext nb_black

JupyterLab: %load_ext lab_black

Snippets:

Writing the same code is boring, and inefficient. There are numerous instances where a code can be reused across different workflows.Code Snippets is a Jupyter extension that allows you to save code as snippets that can then be inserted into Jupyter notebooks on an ad-hoc basis.

The extension for Jupyter notebook can be enabled using the jupyter_contrib_nbextensions whereas for JupyterLab it can be installed using the following command:

pip3 install -U elyra-code-snippet-extension

Creating a new code snippet is simple and intuitive. An example is illustrated below:

GIF by the Author

Closing Thoughts:

  • I believe, Jupyter Notebooks is a powerful tool, and leveraging Jupyter extensions can speed up the development cycle thereby having a direct impact on your efficiency.
  • There are tons of extensions out there that are designed to solve specific bottlenecks in the Jupyter ecosystem. I have covered only the ones that I use regularly.
  • Comment with your favorite Jupyter extension and help the community to be more efficient.

--

--