A faster way to build and share data apps
npx @tessl/cli install tessl/pypi-streamlit@1.50.0A powerful Python framework that transforms Python scripts into interactive web applications in minutes. Streamlit enables developers and data scientists to create dashboards, reports, and chat applications without requiring web development expertise.
pip install streamlitstreamlit run app.pyimport streamlit as stimport streamlit as st
import pandas as pd
import numpy as np
# Set page configuration
st.set_page_config(
page_title="My App",
page_icon="🎯",
layout="wide"
)
# Display title and text
st.title("My Data Dashboard")
st.markdown("Welcome to my **Streamlit** app!")
# Create some sample data
data = pd.DataFrame({
'x': np.random.randn(100),
'y': np.random.randn(100)
})
# Display interactive widgets
name = st.text_input("Enter your name:")
age = st.slider("Select your age:", 0, 100, 25)
show_data = st.checkbox("Show raw data")
# Display charts and data
st.line_chart(data)
if show_data:
st.dataframe(data)
# Display metrics
col1, col2 = st.columns(2)
with col1:
st.metric("Mean X", f"{data['x'].mean():.2f}")
with col2:
st.metric("Mean Y", f"{data['y'].mean():.2f}")
# Create form for user input
with st.form("feedback_form"):
feedback = st.text_area("Provide feedback:")
rating = st.selectbox("Rating:", [1, 2, 3, 4, 5])
submitted = st.form_submit_button("Submit")
if submitted:
st.success(f"Thank you {name}! Rating: {rating}/5")Streamlit follows a reactive programming model built on several key concepts:
st.session_state@st.cache_data and @st.cache_resource decoratorsThis design enables rapid development by treating web apps as simple Python scripts while providing powerful interactive capabilities through automatic state management and efficient UI updates.
Core functions for displaying text, data, charts, and media content. Includes everything from simple text and markdown to interactive dataframes and complex visualizations.
def title(body, anchor=None, *, help=None): ...
def header(body, anchor=None, *, help=None, divider=False): ...
def markdown(body, *, unsafe_allow_html=False, help=None): ...
def dataframe(data, width=None, height=None, *, use_container_width=False, hide_index=None, column_order=None, column_config=None): ...
def line_chart(data, *, x=None, y=None, color=None, width=None, height=None, use_container_width=False, help=None): ...
def image(image, caption=None, width=None, *, use_column_width=None, clamp=False, channels="RGB", output_format="auto", help=None): ...Interactive widgets for user input including buttons, text inputs, selection widgets, file uploads, and form controls.
def button(label, key=None, help=None, on_click=None, args=None, kwargs=None, *, type="secondary", disabled=False, use_container_width=False, icon=None): ...
def text_input(label, value="", max_chars=None, key=None, type="default", help=None, autocomplete=None, on_change=None, args=None, kwargs=None, *, placeholder=None, disabled=False, label_visibility="visible"): ...
def selectbox(label, options, index=0, format_func=str, key=None, help=None, on_change=None, args=None, kwargs=None, *, placeholder="Choose an option", disabled=False, label_visibility="visible"): ...
def slider(label, min_value=None, max_value=None, value=None, step=None, format=None, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False, label_visibility="visible"): ...
def file_uploader(label, type=None, accept_multiple_files=False, key=None, help=None, on_change=None, args=None, kwargs=None, *, disabled=False, label_visibility="visible"): ...Functions for organizing app layout including columns, containers, sidebars, tabs, and expandable sections.
def columns(spec, *, gap="small"): ...
def container(*, height=None, border=None): ...
def expander(label, *, expanded=False, icon=None): ...
def tabs(tab_list): ...
def form(key, *, clear_on_submit=False, border=True): ...Session state, query parameters, and context management for maintaining application state across interactions.
session_state: SessionStateProxy
query_params: QueryParamsProxy
context: ContextProxyCaching decorators and performance optimization tools for efficient data processing and resource management.
def cache_data(func=None, *, ttl=None, max_entries=None, show_spinner=True, persist=None, experimental_allow_widgets=False, hash_funcs=None, validate=None): ...
def cache_resource(func=None, *, ttl=None, max_entries=None, show_spinner=True, validate=None, hash_funcs=None): ...Multi-page application support, navigation controls, and execution flow management.
def set_page_config(page_title=None, page_icon=None, layout="centered", initial_sidebar_state="auto", menu_items=None): ...
def navigation(pages, *, position="sidebar", expanded=True): ...
class Page: ...
def switch_page(page): ...
def rerun(): ...
def stop(): ...User authentication, login/logout functionality, and user information access.
user: UserInfoProxy
def login(provider, *, oauth2=None): ...
def logout(): ...Chat interfaces, app fragments, modal dialogs, and database connections for sophisticated applications.
def chat_message(name, *, avatar=None): ...
def chat_input(placeholder=None, key=None, max_chars=None, on_submit=None, args=None, kwargs=None, *, disabled=False): ...
def fragment(func): ...
def dialog(title, *, width="small"): ...
def connection(name, type=None, **kwargs): ...Custom component framework and column configuration for data editors and dataframes.
# Custom components
components.v1.html(html, *, width=None, height=None, scrolling=False): ...
components.v1.declare_component(name, path=None, url=None): ...
# Column configuration
column_config.TextColumn(label=None, width=None, help=None, disabled=None, required=None, default=None, max_chars=None, validate=None): ...
column_config.NumberColumn(label=None, width=None, help=None, disabled=None, required=None, default=None, min_value=None, max_value=None, step=None, format=None): ...# Sidebar access
sidebar: DeltaGenerator
# Secrets management
secrets: SecretsProxy
# Version information
__version__: str
# Configuration
def get_option(key): ...
def set_option(key, value): ...
# Utility functions
def help(obj): ...
def write(*args, unsafe_allow_html=False): ...
def write_stream(stream, *, help=None): ...
def echo(code_location="above"): ...