Streamlit
Streamlit is an open-source Python library that empowers developers to build and share interactive web applications for data science and machine learning with minimal code. It allows transforming Python scripts into beautiful, interactive apps in minutes, supporting various data libraries and visualizations. The current stable version is 1.55.0, with a regular release cadence bringing new features and improvements.
Warnings
- gotcha Streamlit's reactive model reruns the entire script from top to bottom on every user interaction or code change. Be mindful of expensive operations and use `st.cache_data` or `st.cache_resource` to memoize functions and prevent unnecessary re-execution. Not using caching for heavy computations can lead to slow app performance.
- breaking The `st.experimental_user` command has been removed. Access to user information might require alternative authentication methods or specific deployment configurations.
- deprecated The `add_rows` command, used with `st.dataframe` or `st.table`, has been deprecated. While it may still function, its use is discouraged and it will eventually be removed.
- gotcha Widgets within `st.form` only submit their values and trigger a rerun when the `st.form_submit_button` is clicked. If you need immediate interaction, place widgets outside of a form. Also, `st.button` and `st.download_button` cannot be placed inside `st.form`.
- deprecated `kwargs` support for `st.vega_lite_chart` is deprecated. Configurations should be passed via explicit parameters rather than keyword arguments.
Install
-
pip install streamlit
Imports
- streamlit
import streamlit as st
Quickstart
import streamlit as st
st.title('My First Streamlit App')
name = st.text_input('What is your name?')
if name:
st.write(f'Hello, {name}!')
number = st.slider('Choose a number', 0, 100, 50)
st.write(f'The number is {number}')
# To run this app, save it as a .py file (e.g., app.py) and run `streamlit run app.py` in your terminal.