Developing ClickZetta Lakehouse Applications with Streamlit
Introduction to Streamlit
Streamlit is a powerful Python framework designed for data scientists and engineers to quickly create interactive web applications. With Streamlit, you can easily integrate data analysis, machine learning models, and data visualization into one application without deep knowledge of front-end technologies. The main features of Streamlit include:
- Simple and clear API, easy to get started, no front-end knowledge required.
- Supports Markdown and HTML text rendering for rich text effects.
- Provides a variety of interactive components, such as tables and charts, supporting responsive layouts.
- Active community support and continuous updates.
Overview of the Development Process
The development process of a Streamlit application is very simple. This document will demonstrate, through an example, how to combine Streamlit and the clickzetta-sqlalchemy library to create a simple application that queries the ClickZetta Lakehouse and displays the results.
Environment Preparation
First, ensure that streamlit
and clickzetta-sqlalchemy
are installed in your Python environment. Use the following commands to install them:
Next, in the Streamlit secrets.toml
configuration file (project directory or $HOME/.streamlit/secrets.toml
), add the SQLAlchemy style connection string:
Writing Application Code
Create a file named demo.py
and write the following code:
Running the Application
Use the following command to run the application:
Streamlit will automatically open the local browser and visit http://localhost:8501. You can also manually enter this address in the browser.
Example SQL Query
The following is an example SQL query to retrieve purchase event data from the last 24 hours from ClickZetta Lakehouse:
Advanced Examples
Adding Chart Display
To better display the data, you can use Streamlit's st.plotly_chart
function to present the query results in chart form. First, install the pandas
and plotly
libraries:
Then, add the following code in demo.py
: