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
- st.progress(0) creates a progress bar starting at 0%.
- Inside the loop, the value gradually increases from 0 to 100.
- time.sleep(0.05) slows execution for visualization.
- progress_bar.progress(percent_complete) updates the progress dynamically.
- The argument percent_complete tells Streamlit what percentage to display.
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
- Shows a live-updating percentage.
- Displays a success message when complete.
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
- Model training — show how much of training has completed.
- Data loading — indicate progress while loading data.
- File uploads/downloads — show transfer status.
- Loop tracking — visually track long iterations.
Best Practices
- Keep updates minimal; avoid calling .progress() thousands of times per second.
- Combine with st.spinner() for better user experience.
- Always provide feedback text for clarity.