5 Reasons You Should Be Using Jupyter Notebooks

It seems like everyone is getting into Python these days. Honestly I can’t blame them. You can do just about anything in Python. I have created GUI applications using Pyside. I have written ROS code in Python. I once gave a presentation at PyTexas about how you could talk to an Arduino using nothing but Python and you can even now put Python directly onto a microcontroller. Websites completely written in Python? Yep that’s possible and we often use it for our clients.

As the XKCD comic says, (Python) “Is so simple.”

Python
XKCD 353: Python

https://xkcd.com/353/

But in all seriousness, Python is an incredibly powerful tool. One of the biggest questions we often get from people looking to become coders or that are just looking to add more tools to their toolbox is “what is the best IDE for Python?”

Now that is a bit of a loaded question because it all depends on what exactly it is that you are doing and the person. That’s like asking what is the best flavor of ice cream, it’s purely subjective. That is unless you are talking about what pairs well with peach cobbler and that is ALWAYS Blue Bell Vanilla Bean.

As for IDEs I personally love using Atom, Sublime, and even Visual Studio from time to time. However, when it comes to Python development, 80-90% of my time is spent using a tool called Jupyter Notebooks. What are Jupyter Notebooks you say? Well short story is that it is an incredibly awesome and powerful tool that can really help improve your workflow and save you time.

For those of you unfamiliar with Jupyter Notebooks, here are my “5 Reasons You Should Be Using Jupyter Notebooks.”

 

1. When you are sketching out designs for that new project, you use a notebook/notepad/piece of scratch paper. Why is coding treated differently 
– Jupyter Notebooks is the latest iteration of a project first started by Fernando Perez called iPython. This original project was essentially aimed at providing an interactive Python interpreter that was able to provide a history of what occurred. But what was unique about this was it wasn’t just a history slowly scroll through; it was an index-able history. Meaning, you could query and say what was the result from command 8? Eventually this grew to having it put into a web browser, and has evolved into what we know today as Jupyter Notebooks. The best way to describe this tool to someone who has never seen it or used it, is that it is quite literally a programmer’s notebook in which you can run code in individual cells and it allows you to slowly build up your algorithm, classes, or utilities in a way that is very organic. The biggest thing that I’d say is wrong when writing code directly into an IDE is that lack of interractivity. Sure you can run things in debug mode and slowly work up from there, but that doesn’t really apply when you are just prototyping things out.In Jupyter Notebooks, this is highlighted by the concept of cells. These are blocks of either plain text, HTML, or Python/Julia/R code inside of them that can be run.

 

2. Did I Forget to Mention Inline Graphs?
When you are working in a data science position or performing data analysis, one of the most important things you have to do, is convey the meaning of said data. An incredibly power thing with Jupyter Notebooks is the ability to combine code with images, graphics, and graphs using packages like matplotlib and plotly. There’s something awesome about being able to have a section of code that acts on  something like an SQL database munging data and then generate a graph that is shown immediately underneath the code that was responsible for performing the operation. Great examples data visualization within notebooks can be seen over at the Jupyter Notebooks Gallery on Github.

 

3. They are Easily Shared
One of the reason that Jupyter Notebooks have become so popular outside of the reasons listed above, is the fact that they are easily shared in the same format that you last left your notebook in and can be presented directly on services like GitHub. If you haven’t taken a look at the Official Jupyter Notebook Gallery, you can see a collection of amazing notebooks to understand what I’m talking about.  There you can see notebooks in action and even run the code directly in them. Sure you can share a piece of code very easily in the modern world via services such as GitHub and people can get exact copies of what you have shared with the world, but what makes Jupyter Notebooks unique is being able to share them where people can look at both the code and the results from executing that code. Because of this feature, they have become increasingly popular among lecturers, professors, and students in submitting their work and sharing their results. If you fall into this category, you should also take a look at an amazing project that is part of the Jupyter ecosystem, Nbgrader.

 

4. You Can Easily Build Dashboards and Widgets in Them
As a lot of applications and services move more and more to the web (yes web apps have been the promise of developers since the late 90’s), you often need to quickly prototype interfaces to quickly get to the most optimal solution. Because Jupyter Notebooks support extensions and interactive widgets, Jupyter Notebooks can be amazing platform for building these tools because they are already running within a web browser, support doing things in a mix of Python and Javascript (javascript is required when you develop your own widgets), and there are already a wide range of widgets that you can use as a starting point to build your custom interface. For examples of this and the documentation on it, head over to http://jupyter.org/widgets

 

5. You Can Run Notebooks Remotely on Your Own Server
Because Notebooks run inside a web browser there is some dark magic that is required to run this in order to support multiple Python kernels (these link to your Python environments). Getting into how all of that works is a bit outside of the scope of this post but the reason that I bring it up is that with Jupyter Notebooks, you can run them remotely on a dedicated server. Just like a lot of developers will have certain virtual machines or servers dedicated for development in order to keep their environments clean, you can essentially do the same thing with Jupyter Notebook. If you have run Jupyter Notebooks in the past, you most likely were using the default configuration of launching a notebook server locally. However you can have a dedicated server managing Python environments and host notebooks remotely. If you have ever taken a Udacity Class that used python, this is what you were using. What makes this powerful is that it allows people who have access to the Notebook server to be able to run and execute Python code without having anything installed on their computer locally because it is all be accessed over the web.

Although this didn’t quite make it to my top 5 reasons but another reason you should take a look at using Jupyter Notebooks is because all of the cool kids are using them. Now before you start thinking that I’m advocating to do something just because others are doing it hear me out. When you are trying to learn about what the makers and shakers are working on, it is incredibly valuable to be familiar with the tools they are using when you are going through their work. I don’t know about you but I have mad respect for people like DynamicPaige, James Powell, and Jake VanDerPlas and every time I have seen them talk about what they are working on or give a presentation at a Python conference, it has always been through a Jupyter Notebook. Now you should never blindly follow anyone but it is immensely useful to be familiar with the tools and tricks people are using when you are trying to emulate and learn from them.

 

Now there are a lot of people out there who really don’t like Jupyter Notebooks and I really think that they are trying to use them for scenarios where Jupyter Notebooks were never designed for. Point in case, if you read “5 Reasons Why Jupyter Notebooks Suck” by Alexander Meuller; he talks about things like the inability to test Jupyter notebooks or to use code checkers and etc. The thing that I think most people miss is the entire name, Jupyter Notebooks. When you were in school, did you ever turn in your notebook or rough drafts as the final product. I would hope you didn’t. Jupyter Notebooks are not designed for production but for everything that leads up to writing production code.

Jupyter Notebooks are truly one of my favorite tools and I use them for all kinds of things. If you haven’t given them a try, I’d really recommend it.

For more information on them, take a look at the Youtube videos provided by the Software Carpentry Foundation. These videos are generally hosted via Enthought’s YouTube account as most of the presentations are given at SciPy which is hosted by Enthought.