Jupyter Notebook Extensions

Brian Tracy
6 min readMay 9, 2022

--

the Jupyter logo

Jupyter Notebook is a web-based interactive development environment created by the organization Project Jupyter, a non-profit organization whose described purpose is “to support interactive data science and scientific computing across all programming languages.” It is an indispensable tool available to data scientists but admittedly lacks some functionality out-of-the-box. Fortunately, we can add additional utility to our notebooks to assist with productivity through the use of extensions.

Installation

Before opening a notebook, run this command in your command prompt:

pip install jupyter_contrib_nbextensions && jupyter contrib nbextension install

When you start up Jupyter Notebook after installing extensions, you will see a new tab on the Home Page like this:

location of extensions on the Home Page

Once you click on it, you are met with a large number of configurable extensions that can be enabled (sixty-six extensions currently). Clicking on an extension (not the check box) will allow you to pull up information about the functionality and the parameter settings for that particular extension. You likely will not need every single extension, and not all extensions will be appropriate for every project, but some make a big difference in productivity that you should be aware of. Additionally, this list is nowhere near exhaustive and certainly reflects my own bias in my ideal environment, please feel free to leave a comment with any other input!

My top six extensions are:

Table of Contents

While we can have a very separate debate about how to segment a project into separate notebooks (I often at a minimum have 2 notebooks: one for EDA and one for modeling), any notebook is going to contain lots of markdown, code, and output. It can become difficult as notebooks grow in size and scope to organize code and remember where everything is, and a table of contents is a great way to solve that problem.

This extension (with default parameters set) will allow you to create numbered sections that allow you to organize your notebook using markdown heading cells, displaying a ‘table of contents’ on the left side of the notebook. The use of hashtags allows you to indicate the level of organization with the markdown headers, with each added hashtag adding a ‘.x’ as you can see in this example:

2.2.1 Header would start with ###

You can go six layers deep on the organization (but should you?), and you can click on the tabs next to the main headings to collapse or expand them along with all their subheaders. One other cool feature is you can click any of the headings themselves to take you directly to that section of the notebook. It also helps when adding other markdown text because you can reference a particular section where something else occurred. This is, in my opinion, the best extension when it comes to productivity increase. It also pairs well with…

Collapsable Headings

Examples of collapsable headings from the extension configure page

Just like the collapsable table of contents, the collapsable headings extension adds that functionality to the notebook itself. Each of your section headers gets a control button that can toggle the collapse or uncollapse of the entire section. The default parameters adjust the size of the toggle to match the heading level, so you can collapse entire headings or just subsections. Additionally, there is a toolbar button that allows you to toggle ALL the header cells, which comes in handy in larger notebooks. This extension is separate from the table of contents, but I would consider them linked together to maximize functionality when it comes to organization.

Runtools

This extension allows you more power over how you execute cells in your notebooks. Base Jupyter Notebook will allow you to run all cells or all the cells above or below the currently selected cell. Runtools adds a small column on the left side of each cell that allows the cell to be marked (it will change to a lime green color when marked) like this:

The green cells are marked, the grey is not

Once marked, Runtools allows you to run all marked cells, not just all cells. This is useful when you find yourself restarting your kernel often, instead of scrolling through and running the cells you need to get back to work you can have them marked and just run them all with the click of a button! The extension adds a button that turns on/off a floating toolbar like this:

Runtools button (grey with gears) and toolbar

Honestly, I mainly use this extension to execute marked cells when reloading things after a kernel restart, but there is additional functionality that you may find suited to your notebook needs!

ExecuteTime

showing the execute time under the cell

This extension is one of those that deserve to be folded into base Jupyter Notebook. The display changes depended on the cell execution status. For an executed cell it will show the date and time information when the cell was completed, and for cells awaiting execution it will display the time that cell was queued. The default parameter does not clear the data after restarting the kernel, only if you restart and clear output, which allows you to see when the cell was last executed.

Variable Inspector

example of variable inspector window content

The variable inspector is another one that should be included in base Jupyter Notebook. Enabling this extension allows you to toggle a floating window that shows you information on all variables in the current kernel. Clicking the button on the toolbar that looks like a target will toggle the display of the window; it can be dragged, resized, and collapsed as you need. Within the window, the inspector displays the variable name, type, size and beginning values for a quick snapshot of what you have in memory at the moment. The left-most column (the X) allows you to delete the variable as well!

Python Markdown

how Python Markdown allows embedded variables

This extension may not suit everyone's (or every notebook’s) needs but I think it deserves mentioning. So much of the appeal in Jupyter Notebook is the ability to tell a story with your code. Including explanations and reasoning in markdown cells between cells of code gives the reader a fuller experience of the content within the notebook. Python Markdown allows you to include the values of variables in the markdown language rather than redundantly printing the variable in a prior cell and then referencing the value in the markdown cell below it. It also allows you to embed Latex and images, as you can see from this example in the documentation:

As mentioned, this list is not extensive OR exhaustive of the extensions available to you once installed. These are simply the ones I feel can apply broadly to many users with different needs. I encourage you to explore them all and see what works for you and your development environment. Happy coding!

--

--

Brian Tracy

Aspiring Data Scientist, Amateur Movie Critic, Husband, Father, Donut Enthusiast