st.progress() in Streamlit

The progress method creates a progress bar in Streamlit apps. It helps users visualize the progress of a task (for example, from 0% to 100%).

Syntax

st.progress(value)    

The function parameter value (int or float) specifies the current progress (from 0 to 100). It represents a percentage.

Example: Basic Example.

Python

# Importing the Streamlit library
import streamlit as st
import time

st.title("Progress Bar Example")

# Initialize progress bar at 0%
# It creates a progress bar object
progress_bar = st.progress(0)

# Simulate a long task
for percent_complete in range(101):
    time.sleep(0.05)  # wait for 50 milliseconds
    progress_bar.progress(percent_complete)  # update progress    

Explanation

Example with Text Update

We can combine it with a status text to make the progress more interactive.

Python

import streamlit as st
import time

st.title("Downloading File...")

# Create placeholders
progress_bar = st.progress(0)
status_text = st.empty()

for i in range(101):
    status_text.text(f"Progress: {i}%")
    progress_bar.progress(i)
    time.sleep(0.05)

status_text.text("✅ Download Complete!")
st.success("Task finished successfully!")    

Output Behavior

Resetting or Clearing Progress Bar

To remove or reset the progress bar after finishing a task:

Python

progress_bar.empty()    

Example:

Python

import streamlit as st
import time

progress_bar = st.progress(0)

for i in range(100):
    progress_bar.progress(i + 1)
    time.sleep(0.02)

progress_bar.empty()  # Removes the progress bar
st.write("Progress bar cleared!")    

Use Case Examples

Best Practices