Watch AI Investigation by Doctor Droid on 22nd October.

Building Apps with Streamlit

·

4 min read

How Streamlit enables me to build User Interfaces in Python

Cover Image for Building Apps with Streamlit

My fascination with libraries & packages

Ever since my school days, I was always exposed to Object-Oriented Programming (OOPs). Computer Science was often about how to define classes, how to enable polymorphism between objects, so on and so forth.

About a decade ago, was my first experience in the professional world where I interned at a Computer Vision Lab. My internship's goal was to write a program to convert a million hand-drawn CAD drawings to their digital models. I vaguely remember the Java code but I still clearly remember how I used Tesseract library to implement OCR.

Since then, I've always been quite fascinated about some of the resources that have made solving problems a delightful experience for me as a developer.

Some of my favourite such resources are Pandas and Streamlit. If you're someone who's spent enough time trying to analyse and manipulate data in Python, you might be well aware of Pandas.

Streamlit is another such amazing project.

How and when is Streamlit useful?

As a Python developer, the worst part of my building was typically building UI. While I have evaluated the idea to pick up JS / frameworks, the idea of building UI natively has always been distant from my interests.

Often I'd just create Jupyter notebooks, add good comments / markdown in it and then share it with others with the hope that they would read and make sense of my logic / output.

But the readability of Jupyter notebooks suck.

Code distracts users from trying to make sense of the outputs. Asking users to give input is typically through variables in the code.

Streamlit helps create apps with pretty UI in minutes, ALL IN PYTHON.

import streamlit as st

title = st.text_input("Your Name", "Enter your name")
st.write("The user's name is ", title)

This piece of code converts into a form view where I can take inputs from the user.

If you are a Python developer but want to spin up an interface for your users in minutes, this is the way to go.

Flexibility & Features of the Streamlit Library

As you start building an application's page, you get ideas -- "what if I can get user to enter details and click a button?", "What if I can display a table easily?", "what if I can run complex ML models, API calls and more in the background and instantly supply user with insights?", "what if I can cache data to avoid too many API calls?".

Streamlit's library has been built with so many features that it can accommodate most of the needs of a data-oriented application's frontend.

Over the last one year, whenever I need to create a prototype to get feedback from my users or experiment on an idea, Streamlit is generally my first shot.

I have built many tools using Streamlit. Just last week, I noticed my team was feeling the inertia to add changelogs while publishing new releases in our Github repo. I created a changelog generator app using Streamlit, that takes the repo name and generates the changelogs for a given timeline by analysing the commits.

Changelog generated using the streamlit app

Power of Streamlit community

Apart from the power of the product itself, I was amazed by the community and the extended tooling built around Streamlit.

6 months back, I started working on a prototype for Alert Insights bot for Slack. The objective was to analyse alerts from a Slack channel in a user's workspace and provide them with insights on how they could reduce noise in their channels.

See full app here.

I had an idea of a report that my users wanted but I had no idea of how to make it. Within one night of hacking through my Github Codespaces, I ended up building this prototype. It worked well but it wouldn't have without:

(a) echarts package for Streamlit

(b) Footer component

(c) Pygwalker's compatibility with Streamlit

You know what's common between all three?

They are not made by the creators of Streamlit but are actually made by fellow developers when they felt the need for it. Streamlit has a vibrant community where you can always search, discuss and find answers to any of your how-to questions.

It's wonderful active their forum is. How many supporting packages exist across the ecosystem.

Alternates to Streamlit like Deepnote

Recently, I was playing around with Deepnote -- a cloud based Jupyter Notebook platform -- it has evolved quite a lot. They now provide buttons, apps and many more features.

While their UX suggests they are made for more tightly knit internal data team use-cases, they still seem to have quite some extensive capabilities and are worth a try, especially if you just want to provide a Jupyter notebook style interface to the users.

Streamlit -- https://docs.streamlit.io/

Deepnote -- https://deepnote.com/

Changelog generator -- https://changelog-generator.streamlit.app/