Introduction to Streamlit and Streamlit Components
Tags: python, programming, security
Published: 2022-04-11 19:28:22

#### Streamlit is an open-source app framework for Machine Learning and Data Science teams.
In this article we will show you how to build Streamlit apps and custom Streamlit Components, with the end goal of implementing Auth0 authentication.

### <br>

**TL;DR:** [Streamlit](https://www.streamlit.io/) is an open-source app framework for Machine Learning and Data Science teams. You can create beautiful data apps in hours. All in pure Python. Streamlit was released in October 2019 and was recently [acquired by Snowflake](https://blog.streamlit.io/snowflake-to-acquire-streamlit/). There's huge excitement about it in the Data Science community. It's not just for Data Science, though. With its component extensibility architecture, you can build and integrate most kinds of web frontends into Streamlit apps. My experience with Streamlit can be verified on the official page of [Streamlit Creators](https://streamlit.io/creators).

Don't take my word for it that Streamlit is extremely popular and worth taking a serious look at. Here's a chart I [found](https://towardsdatascience.com/10-features-your-streamlit-ml-app-cant-do-without-implemented-f6b4f0d66d36) showing the extremely rapid adoption rate of Streamlit compared to other similar tools.

![Streamlit Rapid Adoption Rate](https://images.ctfassets.net/23aumh6u8s0i/3G605J2ySvHNW6HwQh0pJ7/68c1f8395aa00320c366f408bf85e415/00_streamlit-rapid-adoption-rate.png)

Why is that so?

### Streamlit focuses on simplicity

> "_How can we make a machine learning script and convert it into an app as simple as possible, so that it basically feels like a scripting exercise?_", Inventor of Streamlit, Adrien Treuille (Ph.D.)

[Streamlit](https://www.streamlit.io/) is a single Python package that you install through `pip`, that gives you a set of functions which:
* Can be _interleaved_ into an existing _ML code script_
* Essentially making the ML code _parameterizable_
* Does a little bit of _layout_, and
* _Magically_ turns your ML code into a _beautiful app_

Inspiration is drawn from Jupyter, ipywidgets, R-Shiny, Voila, React, etc., but more as a guiding light than a software architecture. There are significant technical differences in the implementation of Streamlit, which is based on a [_declarative data flow model_](https://en.wikipedia.org/wiki/Dataflow_programming), not wiring callbacks.

Python frameworks such as [scikit-learn](https://scikit-learn.org/stable/), [spaCy](https://spacy.io/), [Pandas](https://pandas.pydata.org/), and various visualization frameworks such as [Altair](https://altair-viz.github.io/), [Plotly](https://plotly.com/graphing-libraries/) and [Matplotlib](https://matplotlib.org) all work seamlessly with Streamlit.

### Streamlit supports many uses

* Every single data analysis team needs to create apps. They're a focal point - like the bonfire of the team. It's where team members get together and communicate.
* Apps are a crucial part of the ML (data analysis) workflow, especially in a non-trivial project.
* This applies not only to internal apps. Machine learning researchers and data scientists need to build apps for external consumption too. Other teams need to consume models in various different ways, and it ought to be much easier to build the required but different application layers to do that.

I'm a big fan of Streamlit and use it extensively for serious work and play. In a previous job, I had developed several in-house apps that I needed to share externally with clients and colleagues, so adding security and authentication features was imperative. As you'll see in this article, Streamlit's embedded components, extensibility architecture, and native session state management will help realize this security objective.

Here is the [GitHub repository](https://github.com/auth0-blog/streamlit-asehmi) for this article.

## Getting Started with Streamlit

The core Streamlit documentation, discussion forum, and examples gallery are very good. This article will by no means replace them but will serve as an alternative place you can start learning about Streamlit with the specific aim of integrating with Auth0. To get a broader appreciation of Streamlit check out these links: [API Docs](https://docs.streamlit.io/index.html) **|** [Gallery](https://streamlit.io/gallery) **|** [GitHub](https://github.com/streamlit/streamlit) **|** [Discussion Forum](https://discuss.streamlit.io/) **|** [Discord Server](https://discord.gg/bTz5EDYh9Z).

### Quick installation

> To use `Streamlit`, you'll need Python 3.5 or above. I use the [Anaconda Python distribution](https://docs.anaconda.com/anaconda/install/index.html) (conda) and Visual Studio Code IDE with [Python extensions](https://code.visualstudio.com/docs/languages/python), which works well with conda environments.

* Open a `conda console` window
* If necessary, run `conda activate` for the env in which you want to install package requirements. See [managing conda environments](https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html).
* Run one of these commands in the console window:

```bash

$ pip install --upgrade streamlit
# and
$ pip install -r requirements.txt

```

The latter command ensures that all necessary packages for this article are in your Python environment. The [requirements file](https://github.com/auth0-blog/streamlit-asehmi/blob/main/article-1/code/requirements.txt) is in the [GitHub repository](https://github.com/auth0-blog/streamlit-asehmi) for this article.

> Note: Linux and Mac users, please remove the `windows-curses` package from the [requirements file](https://github.com/auth0-blog/streamlit-asehmi/blob/main/article-1/code/requirements.txt). The curses package comes with the Python standard library. In Linux and Mac, the curses dependencies should already be installed, so there are no extra steps needed. On Windows, you need to install one special Python package, `windows-curses`, available on PyPI to add curses support.

[Read more...](https://auth0.com/blog/introduction-to-streamlit-and-streamlit-components/?utm_source=content_synd&utm_medium=sc&utm_campaign=streamlit)