Links

Jupyter Notebook 101

An introduction to Jupyter Notebooks

What are Jupyter Notebooks?

Jupyter Notebook is a document that helps with creating and sharing computational documents. You can imagine a Jupyter Notebook like a Google Doc or a Microsoft word; the difference is it has a different file extension (.ipynb) and the code executed in a REPL (Read-Eval-Print-Loop) fashion.
Jupyter Notebook is an open source project. Many organizations and universities use it for data science, data discovery, and visualization workflows. It is the most popular data science interface.

How does a Jupyter Notebook work?

Jupyter Notebooks are built on the IPython kernel, famous for its REPL (Read-Eval-Print-Loop) capabilities. IPython is a command line terminal through which we can interactively execute python commands.
Jupyter Notebooks contain cells that contain atomic commands, which get executed to get the result from a programming environment, for example, from a server where your app is running or an API from a third-party system.
screenshot of a Jupyter task
Like in any other text document, you can add text content (in Markdown format!)
markdown in a Jupyter Note

What help do they do in runbook automation?

The cloud community and the DevOps/SRE groups increasingly interact with complex systems. Also, DevOps/SRE groups mainly write bash/Perl scripts to automate their workflows, aka Runbooks.
By applying the Jupyter Notebook concept to automate the infrastructure workflows simplifies the task of a DevOps/SRE. It also aids in decoupling and debugging various systems quickly.
PS: Unskript uses Jupyter Notebook under the hood. You could build or consume some knowledge shared by many engineers at the awesome-cloud-ops repo and run it via the Docker container.

Crash Course with Jupyter Notebook

Installation

There are many ways to install and run Jupyter Notebooks. Over the years, cloud platforms and several new-age startups have implemented Jupyter Notebooks - Google Collab, Deepnote, and Naas.ai.
I’m using the Anaconda Distribution of Jupyter Notebook. Search for “anaconda download”; the first link you find is probably from Anaconda.com, which distributes the Jupyter Notebooks and several other products like Anaconda Server.
  1. 1.
    Download and Install the Anaconda Opensource Distribution; it fits our use case to build and run a basic Jupyter Notebook.
  2. 2.
    Open the Anaconda Navigator
screenshot of Anaconda manager
  1. 1.
    Launch Jupyter Notebook! (make you are not launching JupyterLab)
  2. 2.
    A browser tab would be launched at http://localhost:8889/tree
Jupyter screen shot

Building a notebook

Next up, hit New -> Python 3 (ipykernel)

creating a new notebook

Each Jupyter notebook contains multiple cells, which contain Python code. Python code in each cell gets executed when you run the cell. Cells can also be configured for text so that you can input instructions and guidance needed for the following code snippet. (markdown!).
cell menu showing configuration options
Please note each cell carries the programming context from the above cells.

Running it!

A notebook (containing multiple cells) can be run in one go by using Cell -> Run Cells (as shown in the image above).
Alternatively, if you are a command line fan, you can use the below command to run a specific notebook.
> jupyter notebook notebook.ipynb

unSkript and Jupyter Notebooks

As discussed above, unSkript uses opensource Jupyter Notebooks under the hood and provides a seamless way of debugging/triggering complex infrastructure scripts.
unSkript has many open-source runbooks (aka notebooks) at the awesome-cloud-ops GitHub repository. So give us a star and raise an issue if you feel we are missing something.

Resources

Few more resources on getting started to understand Jupyter Notebooks: