Tag Archives: jupyter

Adding Notifications to Long-Running Jupyter Notebook Cells

If you use Jupyter Notebook to run long-running processes, such as machine learning training, then you would probably like to know when the cell finishes executing. There is a neat browser plugin that you can use to help solve this issue called jupyter-notify. It will allow you to have your browser send a pop-up message when the cell finishes executing.

The notification will look something like this:

jupyter-notify sample image

Let’s learn how you can add this notification to your Jupyter Notebook! Continue reading Adding Notifications to Long-Running Jupyter Notebook Cells

Netflix Releases Polynote – A Polyglot Jupyter Notebook Variant

Netflix announced that they are releasing a new piece of open source software that they are calling Polynote. Polynote is an IDE-inspired polyglot notebook that includes first-class Scala support, Python and SQL. Looking at the website, it appears to be built on top of Jupyter Notebook.

Their top goals for the project are reproducibility and visibility. You can read the full announcement with examples on Medium.

This looks like an interesting project and I am curious to see how it impacts Project Jupyter. My personal hope is that Netflix’s work will be useful to the Python community and perhaps enhance Jupyter Notebook and JupyterLab.

I like that it this notebook allows each cell to run a different language out of the box. You can do that with Jupyter Notebook, but doing so is a bit clunky and nowhere near as user-friendly as using a drop-down control like the one that Polynote is using.

It is also interesting that Polynote stores its configuration and dependencies in the notebook’s code itself.

Polynote also supports robust data visualization using Vega and Matplotlib.

Check out Polynote here.

Getting Started with JupyterLab

JupyterLab is the latest package from Project Jupyter. In some ways, it is kind of a replacement for Jupyter Notebook. However the Jupyter Notebook is a separate project from JupyterLab. I like to think of JupyterLab as a kind of web-based Integrated Development Environment that you an use to to work with Jupyter Notebooks as well as using terminals, text editors and code consoles. You might say JupyterLab is a more powerful version of Jupyter Notebook.

Anyway, here are a few of the things that JupyterLab is capable of:

  • Code Consoles – These are coding scratchpads that you can use for running code interactively, kind of like Python’s IDLE
  • Kernel-backed documents – These allow you to enable code in any text file (Markdown, Python, R, etc) that can then be run in the Jupyter kernel
  • Mirrored Notebook cell outputs – This let’s you create simple dashboards
  • Multiple views of the same document – Gives you the ability to live edit documents and see the results in real-time

JupyterLab will allow you to view and handle multiple types of data. You can also display rich output from these formats using various visualizations or Markdown.

For navigation, you can use customizable keyboard shortcuts or key maps from vim, emacs and even SublimeText.

You can add new behavior to your JupyterLab instance via extensions. This includes theming support, file editors and more. Continue reading Getting Started with JupyterLab

Jupyter Notebook 101 Released!

My latest book, Jupyter Notebook 101 is now officially released.

You can purchase it at the following retailers:

You can also download a sample of the book from Leanpub. Get it for $9.99  on Leanpub for a limited time only!

Jupyter Notebook 101 will teach you all you need to know to create and use Notebooks effectively. You can use Jupyter Notebook to help you learn to code, create presentations, and make beautiful documentation.

The Jupyter Notebook is used by the scientific community to demonstrate research in an easy-to-replicate manner.

You will learn the following in Jupyter Notebook 101:

  • How to create and edit Notebooks
  • How to add styling, images, graphs, etc
  • How to configure Notebooks
  • How to export your Notebooks to other formats
  • Notebook extensions
  • Using Notebooks for presentations
  • Notebook Widgets
  • and more!

Working with Jupyter Notebook Widgets

What are Jupyter widgets? A widget is an “eventful python object” that in the case of Jupyter Notebook, resides in the browser and is a user interface element, such as a slider or textbox. Jupyter supports a fairly wide array of widgets including the following:

  • Numeric
  • Boolean
  • Selection
  • String
  • Image
  • Button
  • Output
  • Animation
  • Date picker
  • Color picker
  • Controller (i.e. game controller)
  • Layout

We won’t cover every type of widget in this article, but we will get to see a fairly wide range of them in action. For a full list you can check out the documentation. Or you can run the following code in your Notebook: Continue reading Working with Jupyter Notebook Widgets

Creating Jupyter Notebook Widgets with interact

The Jupyter Notebook has a feature known as widgets. If you have ever created a desktop user interface, you may already know and understand the concept of widgets. They are basically the controls that make up the user interface. In your Jupyter Notebook you can create sliders, buttons, text boxes and much more.

We will learn the basics of creating widgets in this chapter. If you would like to see some pre-made widgets, you can go to the following URL:

These widgets are Notebook extensions that can be installed in the same way that we learned about in my Jupyter extensions article. They are really interesting and well worth your time if you’d like to study how more complex widgets work by looking at their source code. Continue reading Creating Jupyter Notebook Widgets with interact

Jupyter Notebook Debugging

Debugging is an important concept. The concept of debugging is trying to figure out what is wrong with your code or just trying to understand the code. There are many times where I will come to unfamiliar code and I will need to step through it in a debugger to grasp how it works. Most Python IDEs have good debuggers built into them. I personally like Wing IDE for instance. Others like PyCharm or PyDev. But what if you want to debug the code in your Jupyter Notebook? How does that work?

In this chapter we will look at a couple of different methods of debugging a Notebook. The first one is by using Python’s own pdb module. Continue reading Jupyter Notebook Debugging

Testing Jupyter Notebooks

The more you do programming, the more you will here about how you should test your code. You will hear about things like Extreme Programming and Test Driven Development (TDD). These are great ways to create quality code. But how does testing fit in with Jupyter? Frankly, it really doesn’t. If you want to test your code properly, you should write your code outside of Jupyter and import it into cells if you need to. This allows you to use Python’s unittest module or py.test to write tests for your code separately from Jupyter. This will also let you add on test runners like nose or put your code into a Continuous Integration setup using something like Travis CI or Jenkins.

However all is now lost. You can do some testing of your Jupyter Notebooks even though you won’t have the full flexibility that you would get from keeping your code separate. We will look at some ideas that you can use to do some basic testing with Jupyter. Continue reading Testing Jupyter Notebooks

How to Export Jupyter Notebooks into Other Formats

When working with Jupyter Notebook, you will find yourself needing to distribute your Notebook as something other than a Notebook file. The most likely reason is that you want to share the content of your Notebook to non-technical users that don’t want to install Python or the other dependencies necessary to use your Notebook. The most popular solution for exporting your Notebook into other formats is the built-in nbconvert tool. You can use nbconvert to export to the following formats:

  • HTML (–to html)
  • LaTeX (–to latex)
  • PDF (–to pdf)
  • Reveal JS (–to slides)
  • Markdown (md) (–to markdown)
  • ReStructured Text (rst) (–to rst)
  • executable script (–to script)

The nbconvert tool uses Jinja templates to convert your Notebook files (.ipynb) to these other static formats. Jinja is a template engine for Python. The nbconvert tool depends on Pandoc and TeX for some of the conversions that it does. You may need to install these separately on your machine. This is documented on ReadTheDocs. Continue reading How to Export Jupyter Notebooks into Other Formats

Jupyter Notebook Extension Basics

There are several methods of extending the functionality of Jupyter Notebooks. Here are four of them:

  • Kernels
  • IPython kernel extensions
  • Notebook extensions
  • Notebook server extensions

For the purposes of this article, I will be focusing on the third item, Notebook Extensions. However, let’s take a moment and talk about the other three so that you are aware of how they can affect your Notebook. Continue reading Jupyter Notebook Extension Basics