Streamlit makes it easy for you to visualize, mutate, and share data. The API reference is organized by activity type, like displaying data or optimizing performance. Each section includes methods associated with the activity type, including examples.
Browse our API below and click to learn more about any of our available commands! 🎈
Write arguments to the app.
st . write ( "Hello **world**!" )
st . write ( my_data_frame )
st . write ( my_mpl_figure )
Any time Streamlit sees either a variable or literal value on its own line, it automatically writes that to your app using
st.write
"Hello **world**!"
my_data_frame my_mpl_figure
Display string formatted as Markdown.
st
.
markdown
(
"Hello **world**!"
)
Display text in title formatting.
st
.
title
(
"The app title"
)
Display text in header formatting.
st
.
header
(
"This is a header"
)
Display text in subheader formatting.
st
.
subheader
(
"This is a subheader"
)
Display text in small font.
st
.
caption
(
"This is written small caption text"
)
Display a code block with optional syntax highlighting.
st
.
code
(
"a = 1234"
)
Write fixed-width and preformatted text.
st
.
text
(
"Hello world"
)
Display mathematical expressions formatted as LaTeX.
st
.
latex
(
"\int a x^2 \,dx"
)
Display a dataframe as an interactive table.
st
.
dataframe
(
my_data_frame
)
Display a static table.
st
.
table
(
my_data_frame
)
Display a metric in big bold font, with an optional indicator of how the metric changed.
st
.
metric
(
"My metric"
,
42
,
2
)
Display object or string as a pretty-printed JSON string.
st
.
json
(
my_data_frame
)
Display a line chart.
st
.
line_chart
(
my_data_frame
)
Display an area chart.
st
.
area_chart
(
my_data_frame
)
Display a bar chart.
st
.
bar_chart
(
my_data_frame
)
Display a map with points on it.
st
.
map
(
my_data_frame
)
Display a matplotlib.pyplot figure.
st
.
pyplot
(
my_mpl_figure
)
Display a chart using the Altair library.
st
.
altair_chart
(
my_altair_chart
)
Display a chart using the Vega-Lite library.
st
.
vega_lite_chart
(
my_vega_lite_chart
)
Display an interactive Plotly chart.
st
.
plotly_chart
(
my_plotly_chart
)
Display an interactive Bokeh chart.
st
.
bokeh_chart
(
my_bokeh_chart
)
Display a chart using the PyDeck library.
st
.
pydeck_chart
(
my_pydeck_chart
)
Display a graph using the dagre-d3 library.
st
.
graphviz_chart
(
my_graphviz_spec
)
Display a button widget.
clicked
=
st
.
button
(
"Click me"
)
Display a download button widget.
st
.
download_button
(
"Download file"
,
file
)
Display a checkbox widget.
selected
=
st
.
checkbox
(
"I agree"
)
Display a radio button widget.
choice
=
st
.
radio
(
"Pick one"
,
[
"cats"
,
"dogs"
]
)
Display a select widget.
choice
=
st
.
selectbox
(
"Pick one"
,
[
"cats"
,
"dogs"
]
)
Display a multiselect widget. The multiselect widget starts as empty.
choices
=
st
.
multiselect
(
"Buy"
,
[
"milk"
,
"apples"
,
"potatoes"
]
)
Display a slider widget.
number
=
st
.
slider
(
"Pick a number"
,
0
,
100
)
Display a slider widget to select items from a list.
size
=
st
.
select_slider
(
"Pick a size"
,
[
"S"
,
"M"
,
"L"
]
)
Display a single-line text input widget.
name
=
st
.
text_input
(
"First name"
)
Display a numeric input widget.
choice
=
st
.
number_input
(
"Pick a number"
,
0
,
10
)
Display a multi-line text input widget.
text
=
st
.
text_area
(
"Text to translate"
)
Display a date input widget.
date
=
st
.
date_input
(
"Your birthday"
)
Display a time input widget.
time
=
st
.
time_input
(
"Meeting time"
)
Display a file uploader widget.
data
=
st
.
file_uploader
(
"Upload a CSV"
)
Display a widget that allows users to upload images directly from a camera.
image
=
st
.
camera_input
(
"Take a picture"
)
Display a color picker widget.
color
=
st
.
color_picker
(
"Pick a color"
)
Display an image or list of images.
st . image ( numpy_array )
st . image ( image_bytes )
st . image ( file )
st . image ( "https://example.com/myimage.jpg" )
Display an audio player.
st . audio ( numpy_array )
st . audio ( audio_bytes )
st . audio ( file )
st . audio ( "https://example.com/myaudio.mp3" , format = "audio/mp3" )
Display a video player.
st . video ( numpy_array )
st . video ( video_bytes )
st . video ( file )
st . video ( "https://example.com/myvideo.mp4" , format = "video/mp4" )
Display items in a sidebar.
st . sidebar . write ( "This lives in the sidebar" )
st . sidebar . button ( "Click me!" )
Insert containers laid out as side-by-side columns.
col1 , col2 = st . columns ( 2 )
col1 . write ( "this is column 1" )
col2 . write ( "this is column 2" )
Insert a multi-element container that can be expanded/collapsed.
with st . expander ( "Open to see more" ) :
st . write ( "This is more content" )
Insert a multi-element container.
c = st . container ( )
st . write ( "This will show last" )
c . write ( "This will show first" )
c . write ( "This will show second" )
Insert a single-element container.
c = st . empty ( )
st . write ( "This will show last" )
c . write ( "This will be replaced" )
c . write ( "This will show first" )
Display a progress bar.
for i in range ( 101 ) :
st . progress ( i )
do_something_slow ( )
Temporarily displays a message while executing a block of code.
with st . spinner ( "Please wait..." ) :
do_something_slow ( )
Display celebratory balloons!
do_something ( ) # Celebrate when all done!
st . balloons ( )
Display celebratory snowflakes!
do_something ( ) # Celebrate when all done!
st . snow ( )
Display error message.
st
.
error
(
"We encountered an error"
)
Display warning message.
st
.
warning
(
"Unable to fetch image. Skipping..."
)
Display an informational message.
st
.
info
(
"Dataset is updated every day at midnight."
)
Display a success message.
st
.
success
(
"Match found!"
)
Display an exception.
e = RuntimeError ( "This is an exception of type RuntimeError" )
st . exception ( e )
Create a form that batches elements together with a “Submit” button.
with st . form ( key = 'my_form' ) :
username <span class="token operator">
= st . text_input ( "Username" )
password <span class="token operator">
= st . text_input ( "Password" )
st<span class="token punctuation">
. form_submit_button ( "Login" )
Stops execution immediately.
st
.
stop
(
)
Rerun the script immediately.
st
.
experimental_rerun
(
)
Configures the default settings of the page.
st
.
set_page_config
(
title
=
"My app"
,
favicon
=
":shark:"
,
)
Display some code on the app, then execute it. Useful for tutorials.
with st . echo ( ) :
st . write ( 'This code will be printed' )
Display object’s doc string, nicely formatted.
st . help ( st . write )
st . help ( pd . DataFrame )
Write arguments and argument names to your app for debugging purposes.
df = pd . DataFrame ( { 'first column' : [ 1 , 2 , 3 , 4 ] , 'second column' : [ 10 , 20 , 30 , 40 ] , } )
st . experimental_show ( df )
Return the query parameters that are currently showing in the browser's URL bar.
st
.
experimental_get_query_params
(
)
Set the query parameters that are shown in the browser's URL bar.
st
.
experimental_set_query_params
(
show_map
=
True
,
selected
=
[
"asia"
]
)
Append a dataframe to the bottom of the current one in certain elements, for optimized data updates.
element = st . line_chart ( df )
element . add_rows ( df_with_extra_rows )
Session state is a way to share variables between reruns, for each user session.
st
.
session_state
[
'key'
]
=
value
Function decorator to memoize function executions.
@st
.
cache
(
ttl
=
3600
)
def
run_long_computation
(
arg1
,
arg2
)
:
# Do stuff here
return
computation_output
Experimental function decorator to memoize function executions.
@st
.
experimental_memo
def
fetch_and_clean_data
(
url
)
:
# Fetch data from URL here, and then clean it up.
return
data
Experimental function decorator to store singleton objects.
@st
.
experimental_singleton
def
get_database_session
(
url
)
:
# Create a database session object that points to the URL.
return
session
Clear all in-memory and on-disk memo caches.
@st . experimental_memo def fetch_and_clean_data ( url ) : # Fetch data from URL here, and then clean it up. return data if st . checkbox ( "Clear All" ) : # Clear values from *all* memoized functions
st . experimental_memo . clear ( )
Clear all singleton caches.
@st . experimental_singleton def get_database_session ( url ) : # Create a database session object that points to the URL. return session if st . button ( "Clear All" ) : # Clears all singleton caches:
st . experimental_singleton . clear ( )
st.experimental_user
returns information about the logged-in user of private apps on Streamlit Cloud.
if st . experimental_user . email == "foo@corp.com" :
st . write ( "Welcome back, " , st . experimental_user . email )
else :
st . write ( "You are not authorized to view this page." )
Was this page helpful?