Getting Started with Zero-True Notebook

Red Giuliano
Zero-True
Published in
5 min readOct 23, 2023

A new, reactive python notebook built to help data practitioners seamlessly go from data exploration to interactive publication.

Reactive Code cells in Zero-True notebook, image by author

Intro:

Sharing a code notebook with non technical stakeholders can be a relatively painful process, especially in today’s world where so many meetings are remote. Most of the time I used to have to resort to simply sharing my notebook as some sort of static document… I’d either pull insights into a PDF, deck or spreadsheet and most of the magic of my insights would be dulled down. With Zero-True notebook however, I can share my notebook directly with non technical stakeholders as a live application! Let’s get started and just create a super basic example!

Zero True vs Current Sharing Stack, image by author

Installation and Startup

To get started simply run the following command (setting up in a virtual environment is recommended of course).

pip install zero-true

Then navigate to whatever folder you’d like and run:

zero-true notebook

You will see a display in your command line prompting you to navigate to http://localhost:1326. Click on this link and you will see your notebook appear!

Getting Started

Zero-True is built to feel like a Jupyter notebook, but has several quality of life improvements that are meant to make you more productive and help you share your insights. To get started with our built in UI library simply run the following code:

Cell 1:

import zero_true as zt
slider = zt.Slider(id='slider_1')
print('The squared value is '+str(slider.value**2))

You’ll see that a slider appears below your code cell and that every time you drag it you get the squared value back!

Python + SQL in a Zero-True Notebook

Let’s move on to a more complicated example. We will be combining SQL+Python using Zero-True’s built in SQL editor powered by duckdb. To get started let’s install the popular machine learning library sklearn and play around with one of their datasets. First let’s install sklearn if we haven’t already:

pip install scikit-learn

Now let’s edit the first cell to load in the Iris dataset and display the table in our browser:

import zero_true as zt
import sklearn
import pandas as pd
from sklearn import datasets
iris = datasets.load_iris()
iris_df = pd.DataFrame(data=iris.data, columns=iris.feature_names)
slider = zt.Slider(id='slider_1')
zt.DataFrame.from_dataframe(id='iris_df',df = iris_df)
Displaying a dataframe and a slider with Zero-True

Pretty neat.. I’ve always seen this dataset used in tutorials but have never played around with it myself. Let’s use Zero-True’s built in UI components and SQL editor to build an interface that let’s users query our data. The first step is to add a sql cell below the current cell.

Adding a SQL Cell at the click of a button!

Next let’s run a couple SQL queries on our pandas dataframe. Yep, thanks to duck db you can rely on SQL when you know that writing the same query in pandas would be a pain. I know that in this case our queries will be basic but the goal of this article is just a simple example of what is possible with Zero-True.

Now we can finally wrap this up. Since all these columns are numeric we can define some range sliders to allow users to filter down the data in our sql query. This is what our first cell looks like now:

Cell 1:

import zero_true as zt
import sklearn
import pandas as pd
from sklearn import datasets
iris = datasets.load_iris()
iris_df = pd.DataFrame(data=iris.data, columns=iris.feature_names)
#rename columns without spaces
iris_df.columns = [ col.replace(' ','_').replace('(cm)','cm') for col in iris_df.columns]#all the different sliders
sepal_width_slider = zt.RangeSlider(id = 'sepal_width',
min = iris_df.sepal_width_cm.min(),
max = iris_df.sepal_width_cm.max(),
step = 0.1,label = 'Sepal Width')
petal_width_slider = zt.RangeSlider(id = 'petal_width',
min = iris_df.petal_width_cm.min(),
max = iris_df.petal_width_cm.max(),
step = 0.1,label = 'Petal Width')
sepal_length_slider = zt.RangeSlider(id = 'sepal_length',
min = iris_df.sepal_length_cm.min(),
max = iris_df.sepal_length_cm.max(),
step = 0.1, label = 'Sepal Length')
petal_length_slider = zt.RangeSlider(id = 'petal_lenght',
min = iris_df.petal_length_cm.min(),
max = iris_df.petal_length_cm.max(),
step = 0.1, label = 'Petal Length')

Now we write our SQL cell below:

Cell 2:

SELECT * FROM iris_df
WHERE (sepal_length_cm BETWEEN {sepal_length_slider.value[0]} AND {sepal_length_slider.value[1]})
AND (sepal_width_cm BETWEEN {sepal_width_slider.value[0]} AND {sepal_width_slider.value[1]})
AND (petal_width_cm BETWEEN {petal_width_slider.value[0]} AND {petal_width_slider.value[1]})
AND (petal_length_cm BETWEEN {petal_length_slider.value[0]} AND {petal_length_slider.value[1]})

As you can see we can seamlessly interface between the UI components we defined in python and the pandas dataframe we built in the first cell, with the built in SQL editor. At this point we have a UI that can be safely shared with anyone. We parse your query into a prepared statement on the backend so you can use intuitive syntax with no threat of SQL injection.

If you want to see what your notebook will look like as a shareable interface, simply run

zero-true app

from the same directory as your notebook and you will see a live preview of what your notebook looks like as an app! If you want to do that though you might just have to install the package and try it for yourself…

Publishing your notebook

Publishing your notebook is currently in closed beta, but it’s as easy as running

zero-true publish [api-key] [user-name] [project-name] [project-source]

To see our app live and in action visit at:

https://published.zero-true-cloud.com/examples/iris/

Publishing with Zero-True let’s you deploy and share your work without the headache of having to manage your own infrastructure. Let us know if this is something you and your team might be interested…

Conclusion

Thanks so much for reading this far! I hope that Zero-True notebook will help you and your teams bring your data to the forefront of your organization! If you liked the tutorial and the package, please do star us on github at https://github.com/Zero-True/zero-true! Thanks so much once again!

--

--