Snowflake for Beginners Part 3: From Snowflake Data to a Working Streamlit App

In the first two parts of this series, most of my work happened inside Snowflake.

I loaded files, created tables, queried data and then learned how Snowflake handles JSON.

The next badge introduced something different.

Instead of only working with the data myself, I started building something another person could actually use:

a smoothie ordering application.

Before looking at any code, I think the easiest way to understand this is to first see what we are actually building.

The finished application lets the user:

  • enter their name
  • choose up to five ingredients
  • see information about those ingredients
  • submit their order

There is actually quite a lot happening behind what looks like a simple screen.

The finished version uses things such as:

Streamlit, Python, Snowflake, Snowpark, an API, Pandas and GitHub.

When I first saw all of those pieces together, that was the part I found confusing.

I could follow individual lines of code, but I was not always clear on the bigger question:

Where is the data coming from, where is it going, and what is each tool actually doing?

So rather than starting with lots of code, I want to start with the application itself and work backwards.

In this post I will focus on the foundation:

User → Streamlit → Python → Snowflake

We will look at both:

the code we write

and

what that code actually creates in the application.

You may notice that my finished app also displays nutrition information.

I am deliberately leaving that part until the next post.

That is where we will introduce APIs and JSON and see how Python can request information from another system and bring it into our Streamlit app.

For now, the first question is:

How does a user interact with Snowflake data through a Streamlit application?

The big picture first

Before looking at the individual commands, this is the flow I needed to understand.

When the application needs to show available fruits:

Plain text
SNOWFLAKE
    ↓
PYTHON
    ↓
STREAMLIT
    ↓
USER

But when the user submits an order, the information travels the other way:

Plain text
USER
    ↓
STREAMLIT
    ↓
PYTHON
    ↓
SNOWFLAKE

That is the main idea behind the application.

Information is moving between different components.

Once I understood those roles, the individual lines of code stopped feeling quite so random.


Step 1: Start with something the user can see

At the beginning of the Python file we import Streamlit:

Python
import streamlit as st

The important part for now is:

Plain text
as st

This means we can use the shorter name:

Plain text
st

instead of writing streamlit every time.

That is why many of the commands in the application begin with:

Plain text
st.

For example:

Plain text
st.title(":cup_with_straw: Customize Your Smoothie! :cup_with_straw:")

CODE

Plain text
st.title(":cup_with_straw: Customize Your Smoothie! :cup_with_straw:")

RESULT IN THE APP

Plain text
🥤 Customize Your Smoothie! 🥤

So I now read:

Plain text
st.title(...)

as:

Streamlit, display this as a title in my application.

This is a very simple example, but it shows the basic idea behind Streamlit.

We write Python.

Streamlit turns it into something the user can see.


Step 2: Let the user enter information

A useful application also needs the user to interact with it.

My app contains:

Plain text
name_on_order = st.text_input('Name on Smoothie:')

This creates the text box we can see in the application.

CODE

Plain text
name_on_order = st.text_input('Name on Smoothie:')

RESULT

Plain text
Name on Smoothie:

[ Zain __________________ ]

But there is something more important happening behind the screen.

If I type:

Plain text
Zain

Streamlit captures that value.

Because I wrote:

Plain text
name_on_order =

Python stores the answer inside a variable called:

Plain text
name_on_order

So conceptually:

Plain text
USER TYPES

"Zain"

      ↓

STREAMLIT CAPTURES IT

      ↓

PYTHON STORES IT

name_on_order = "Zain"

This was an important point for me.

Streamlit is not only displaying information.

It is also a way of collecting information from the user and passing it into Python.

My code then contains:

Plain text
st.write(
    'The name on your Smoothie will be:',
    name_on_order
)

So when I type:

Plain text
Zain

the application displays:

Plain text
The name on your Smoothie will be: Zain

We already have our first little flow:

Plain text
USER
 ↓
STREAMLIT TEXT BOX
 ↓
PYTHON VARIABLE
 ↓
STREAMLIT DISPLAYS IT

Step 3: Now we need Snowflake

So far our application only involves:

Plain text
USER ↔ STREAMLIT ↔ PYTHON

But the fruit choices are stored in Snowflake.

The next thing we need is a way for Python to communicate with Snowflake.

In the finished external version of my application I use:

Plain text
cnx = st.connection("snowflake")
session = cnx.session()

When I first saw terms such as connection and session, they sounded more complicated than they really were.

I now think of it like this:

Plain text
PYTHON
   ↓
CONNECTION
   ↓
SNOWFLAKE

First:

Plain text
cnx = st.connection("snowflake")

means roughly:

Connect my Streamlit application to Snowflake.

Then:

Plain text
session = cnx.session()

gives Python a Snowflake session.

The simplest way I think about a session is:

An active route that allows my Python code to communicate with Snowflake.

Once we have the session, Python can start asking Snowflake for data.


Why did my connection code change?

This was one of the things that confused me during the badge.

Originally, the Streamlit application was running inside Snowflake.

The code used:

SQL
from snowflake.snowpark.context import get_active_session

session = get_active_session()

Later, I moved the application outside Snowflake.

My GitHub version uses:

Plain text
cnx = st.connection("snowflake")
session = cnx.session()

At first this looked like we were doing something completely different.

But the purpose is actually the same.

We need:

A Snowflake session that Python can use to communicate with Snowflake.

What changed was where the application was running.

Inside Snowflake

Plain text
APPLICATION IS ALREADY IN SNOWFLAKE
              ↓
GET EXISTING ACTIVE SESSION

External Streamlit application

SQL
APPLICATION IS OUTSIDE SNOWFLAKE
              ↓
CREATE CONNECTION
              ↓
GET SNOWFLAKE SESSION

The syntax changed.

The purpose did not.


Step 4: Ask Snowflake for the fruit choices

Now Python has a route into Snowflake.

The next thing we need is the list of fruits the user can select.

My final application contains:

SQL
my_dataframe = session.table(
    "smoothies.public.fruit_options"
).select(
    col('FRUIT_NAME'),
    col('SEARCH_ON')
)

There is an extra column called:

Plain text
SEARCH_ON

in my finished version.

That becomes important when we introduce the API, so I will explain it properly in another post.

For now, focus on:

Plain text
FRUIT_NAME

First:

Plain text
session.table(
    "smoothies.public.fruit_options"
)

means:

Using my Snowflake session, go to this Snowflake table.

Then:

SQL
.select(
    col('FRUIT_NAME')
)

means:

From that table, I want the FRUIT_NAME information.

The result is stored in:

Plain text
my_dataframe

So:

Plain text
SNOWFLAKE

FRUIT_OPTIONS TABLE
       ↓
Python requests FRUIT_NAME
       ↓
my_dataframe

What is a DataFrame?

This was another term that initially sounded more technical than it needed to.

For now, the easiest way I think about a DataFrame is:

A table-like object that Python can work with.

For example:

Plain text
FRUIT_NAME
----------------
Apples
Cantaloupe
Mango
Orange
Lime

The original data lives in Snowflake.

But Python now has a way to work with that table-like data.

At this point we are using a Snowpark DataFrame.

Later in the badge I also use a Pandas DataFrame.

They are not exactly the same thing, so I will leave that distinction for a later post rather than mixing everything together here.


Step 5: Turn Snowflake data into something the user can select

Now we start connecting the pieces together.

My application contains:

Plain text
ingredients_list = st.multiselect(
    "Choose up to 5 ingredients:",
    my_dataframe,
    max_selections=5
)

CODE

Plain text
ingredients_list = st.multiselect(
    "Choose up to 5 ingredients:",
    my_dataframe,
    max_selections=5
)

RESULT IN MY APP

Plain text
Choose up to 5 ingredients:

[Apples] [Cantaloupe] [Mango] [Orange]

This is where only looking at the Python code can hide what is really happening.

Those fruit choices did not magically appear inside Streamlit.

They travelled through the application:

Plain text
FRUIT_OPTIONS TABLE
IN SNOWFLAKE

       ↓

Python uses session.table()

       ↓

my_dataframe

       ↓

st.multiselect()

       ↓

USER SEES FRUIT CHOICES

This was one of the main moments where the idea of a data application clicked for me.

I was taking values stored in Snowflake and using them to control what appeared inside a web application.


Step 6: What happens when the user chooses fruits?

In my screenshot I selected:

Plain text
Apples
Cantaloupe
Mango
Orange

Streamlit stores those selections inside:

Plain text
ingredients_list

Conceptually, Python now has something similar to:

JSON
["Apples", "Cantaloupe", "Mango", "Orange"]

This is a Python list.

The application then goes through the selected fruits.

Plain text
ingredients_string = ''

for fruit_chosen in ingredients_list:
    ingredients_string += fruit_chosen + ' '

First:

Plain text
ingredients_string = ''

means:

Start with an empty piece of text.

Then:

Plain text
for fruit_chosen in ingredients_list:

means:

Go through each fruit the user selected, one at a time.

So Python effectively goes:

Plain text
fruit_chosen = Apples

then

fruit_chosen = Cantaloupe

then

fruit_chosen = Mango

then

fruit_chosen = Orange

And:

Plain text
ingredients_string += fruit_chosen + ' '

keeps adding each fruit onto the text.

Eventually we might have:

Plain text
Apples Cantaloupe Mango Orange

So:

Plain text
USER SELECTION

[Apples, Cantaloupe, Mango, Orange]

              ↓

      PYTHON PROCESSES LIST

              ↓

"Apples Cantaloupe Mango Orange"

Now we have something that can be stored as part of the order.


Step 7: Give the user a Submit button

My application also contains:

Plain text
time_to_insert = st.button('Submit Order')

RESULT

Plain text
[ Submit Order ]

The code then uses:

Plain text
if time_to_insert:

which basically means:

If the user has pressed Submit Order, run the code underneath.

So the button controls when Python performs the next action.


Step 8: Send the order back into Snowflake

At this stage Python has things such as:

Plain text
name_on_order = "Zain"

and:

Plain text
ingredients_string =
"Apples Cantaloupe Mango Orange"

We now want to save those values into the Snowflake ORDERS table.

The code builds an SQL statement similar to:

SQL
my_insert_stmt = """
insert into smoothies.public.orders
(ingredients, name_on_order)
values ('""" + ingredients_string + """','""" + name_on_order + """')
"""

When I first looked at this, the mixture of quotes made it look much more complicated than the idea behind it.

What Python is effectively creating is:

SQL
INSERT INTO smoothies.public.orders
(ingredients, name_on_order)
VALUES (
    'Apples Cantaloupe Mango Orange',
    'Zain'
);

Which simply means:

Add a new row to the ORDERS table containing this person's name and selected ingredients.

Python then sends the SQL to Snowflake:

Plain text
session.sql(my_insert_stmt).collect()

The important flow is:

SQL
USER PRESSES SUBMIT
        ↓
PYTHON HAS NAME + INGREDIENTS
        ↓
PYTHON CREATES SQL INSERT
        ↓
SQL SENT TO SNOWFLAKE
        ↓
NEW ORDER STORED

The workshop builds the SQL directly from the user's values so that the process is easy to see.

In a production application, I would normally use a safer parameterised approach when dealing with user-entered values rather than directly joining user input into SQL.


Step 9: Tell the user their order was successful

After Snowflake receives the order, Streamlit can display a confirmation.

Plain text
st.success(
    'Your Smoothie is ordered, '
    + name_on_order + '!',
    icon="✅"
)

If:

Plain text
name_on_order = Zain

the application can display:

Plain text
✅ Your Smoothie is ordered, Zain!

We have now completed the full journey:

Plain text
USER
enters name + chooses fruits
        ↓
STREAMLIT
captures those choices
        ↓
PYTHON
processes them
        ↓
SNOWFLAKE
stores the order
        ↓
STREAMLIT
confirms it worked

The important idea: READ vs WRITE

This was probably the simplest way for me to understand the whole application.

READ

When the app needs the available fruits:

Plain text
SNOWFLAKE
    ↓
PYTHON
    ↓
STREAMLIT
    ↓
USER

The application is reading from Snowflake.

WRITE

When the user submits an order:

Plain text
USER
    ↓
STREAMLIT
    ↓
PYTHON
    ↓
SNOWFLAKE

The application is writing to Snowflake.


Where does GitHub fit?

The finished application now lives inside my GitHub repository.

This introduced another useful distinction.

Plain text
GITHUB
= application CODE

SNOWFLAKE
= application DATA

GitHub stores and tracks files such as:

Plain text
streamlit_app.py

and:

Plain text
requirements.txt

The Python file contains the application code.

The requirements file tells the environment which Python packages the application needs.

My finished application uses:

Plain text
snowflake-snowpark-python
streamlit
requests
pandas

I am deliberately not explaining requests and pandas yet.

Those become important when we look at the API section of the application.


What about passwords?

Because the external Streamlit application connects to Snowflake, it needs connection information.

But I do not want things such as my Snowflake password written directly inside:

Plain text
streamlit_app.py

especially if that file is stored publicly on GitHub.

Instead, these values are stored separately as secrets.

I think of secrets as:

A locked drawer containing information the application needs but should not expose publicly.

So:

Plain text
PUBLIC APPLICATION CODE
          ↓
needs Snowflake connection
          ↓
SECRETS PROVIDE CREDENTIALS
          ↓
SNOWFLAKE

The complete application flow

We started with a simple goal:

Let someone order a smoothie without needing to know Python or SQL.

Behind that simple interface:

SQL
1. User opens the Streamlit app
             ↓
2. Python connects to Snowflake
             ↓
3. Python retrieves the available fruits
             ↓
4. Streamlit displays those fruits
             ↓
5. User enters their name
             ↓
6. User selects ingredients
             ↓
7. Streamlit passes those values to Python
             ↓
8. User presses Submit
             ↓
9. Python sends an INSERT to Snowflake
             ↓
10. Snowflake stores the order
             ↓
11. Streamlit confirms the order

The concepts I would remember

Streamlit — creates the interface the user sees and interacts with.

Python — controls the application logic and connects the different parts together.

Snowflake — stores and returns the application's data.

Snowpark — allows Python to work with Snowflake.

Session — the active route Python uses to communicate with Snowflake.

GitHub — stores and tracks the application code.

Secrets — keep sensitive connection information away from the public code.


Final takeaway

The biggest thing I learned from this part of the badge was not memorising every Streamlit or Snowpark function.

It was understanding:

Where is the information coming from, where is it going, and what is moving it?

The simplest version is:

Plain text
USER
 ↓
STREAMLIT
 ↓
PYTHON
 ↓
SNOWFLAKE

And when we retrieve information, it travels back:

Plain text
SNOWFLAKE
 ↓
PYTHON
 ↓
STREAMLIT
 ↓
USER

Once I understood that flow, the code stopped looking like a collection of random commands.

Each line had a reason for being there.

My finished application contains another important part that I have deliberately not explained in this post.

When I choose Apples, for example, the application can display:

Apples Nutrition Information.

That information does not come from my Snowflake FRUIT_OPTIONS table.

Python requests it from another system using an API.

That is what I will explore in the next part:

What is an API, what does requests.get() actually do, and how does JSON data from another system end up appearing inside a Streamlit application?

Author:
Zainul Abedin Natha
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2026 The Information Lab