- Spec files
pypi-streamlit
Describes: pkg:pypi/streamlit@1.50.x
- Description
- A faster way to build and share data apps
- Author
- tessl
- Last updated
index.md docs/
1# Streamlit23A 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.45## Package Information67- **Package Name**: streamlit8- **Language**: Python9- **Installation**: `pip install streamlit`10- **CLI Command**: `streamlit run app.py`1112## Core Imports1314```python15import streamlit as st16```1718## Basic Usage1920```python21import streamlit as st22import pandas as pd23import numpy as np2425# Set page configuration26st.set_page_config(27page_title="My App",28page_icon="🎯",29layout="wide"30)3132# Display title and text33st.title("My Data Dashboard")34st.markdown("Welcome to my **Streamlit** app!")3536# Create some sample data37data = pd.DataFrame({38'x': np.random.randn(100),39'y': np.random.randn(100)40})4142# Display interactive widgets43name = st.text_input("Enter your name:")44age = st.slider("Select your age:", 0, 100, 25)45show_data = st.checkbox("Show raw data")4647# Display charts and data48st.line_chart(data)4950if show_data:51st.dataframe(data)5253# Display metrics54col1, col2 = st.columns(2)55with col1:56st.metric("Mean X", f"{data['x'].mean():.2f}")57with col2:58st.metric("Mean Y", f"{data['y'].mean():.2f}")5960# Create form for user input61with st.form("feedback_form"):62feedback = st.text_area("Provide feedback:")63rating = st.selectbox("Rating:", [1, 2, 3, 4, 5])64submitted = st.form_submit_button("Submit")6566if submitted:67st.success(f"Thank you {name}! Rating: {rating}/5")68```6970## Architecture7172Streamlit follows a reactive programming model built on several key concepts:7374- **Script Re-execution**: The entire script re-runs when user interactions change widget values75- **Session State**: Persistent state management across script re-runs via `st.session_state`76- **Caching**: Performance optimization through `@st.cache_data` and `@st.cache_resource` decorators77- **Delta Generator**: Core abstraction that manages the display tree and updates efficiently78- **Widget State**: Automatic state tracking for all input widgets with optional callbacks7980This 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.8182## Capabilities8384### Display Elements8586Core functions for displaying text, data, charts, and media content. Includes everything from simple text and markdown to interactive dataframes and complex visualizations.8788```python { .api }89def title(body, anchor=None, *, help=None): ...90def header(body, anchor=None, *, help=None, divider=False): ...91def markdown(body, *, unsafe_allow_html=False, help=None): ...92def dataframe(data, width=None, height=None, *, use_container_width=False, hide_index=None, column_order=None, column_config=None): ...93def line_chart(data, *, x=None, y=None, color=None, width=None, height=None, use_container_width=False, help=None): ...94def image(image, caption=None, width=None, *, use_column_width=None, clamp=False, channels="RGB", output_format="auto", help=None): ...95```9697[Display Elements](./display-elements.md)9899### Input Widgets100101Interactive widgets for user input including buttons, text inputs, selection widgets, file uploads, and form controls.102103```python { .api }104def button(label, key=None, help=None, on_click=None, args=None, kwargs=None, *, type="secondary", disabled=False, use_container_width=False, icon=None): ...105def 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"): ...106def 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"): ...107def 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"): ...108def 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"): ...109```110111[Input Widgets](./input-widgets.md)112113### Layout and Containers114115Functions for organizing app layout including columns, containers, sidebars, tabs, and expandable sections.116117```python { .api }118def columns(spec, *, gap="small"): ...119def container(*, height=None, border=None): ...120def expander(label, *, expanded=False, icon=None): ...121def tabs(tab_list): ...122def form(key, *, clear_on_submit=False, border=True): ...123```124125[Layout and Containers](./layout-containers.md)126127### State Management128129Session state, query parameters, and context management for maintaining application state across interactions.130131```python { .api }132session_state: SessionStateProxy133query_params: QueryParamsProxy134context: ContextProxy135```136137[State Management](./state-management.md)138139### Caching and Performance140141Caching decorators and performance optimization tools for efficient data processing and resource management.142143```python { .api }144def cache_data(func=None, *, ttl=None, max_entries=None, show_spinner=True, persist=None, experimental_allow_widgets=False, hash_funcs=None, validate=None): ...145def cache_resource(func=None, *, ttl=None, max_entries=None, show_spinner=True, validate=None, hash_funcs=None): ...146```147148[Caching and Performance](./caching-performance.md)149150### Navigation and Pages151152Multi-page application support, navigation controls, and execution flow management.153154```python { .api }155def set_page_config(page_title=None, page_icon=None, layout="centered", initial_sidebar_state="auto", menu_items=None): ...156def navigation(pages, *, position="sidebar", expanded=True): ...157class Page: ...158def switch_page(page): ...159def rerun(): ...160def stop(): ...161```162163[Navigation and Pages](./navigation-pages.md)164165### User and Authentication166167User authentication, login/logout functionality, and user information access.168169```python { .api }170user: UserInfoProxy171def login(provider, *, oauth2=None): ...172def logout(): ...173```174175[User and Authentication](./user-auth.md)176177### Advanced Features178179Chat interfaces, app fragments, modal dialogs, and database connections for sophisticated applications.180181```python { .api }182def chat_message(name, *, avatar=None): ...183def chat_input(placeholder=None, key=None, max_chars=None, on_submit=None, args=None, kwargs=None, *, disabled=False): ...184def fragment(func): ...185def dialog(title, *, width="small"): ...186def connection(name, type=None, **kwargs): ...187```188189[Advanced Features](./advanced-features.md)190191### Components and Configuration192193Custom component framework and column configuration for data editors and dataframes.194195```python { .api }196# Custom components197components.v1.html(html, *, width=None, height=None, scrolling=False): ...198components.v1.declare_component(name, path=None, url=None): ...199200# Column configuration201column_config.TextColumn(label=None, width=None, help=None, disabled=None, required=None, default=None, max_chars=None, validate=None): ...202column_config.NumberColumn(label=None, width=None, help=None, disabled=None, required=None, default=None, min_value=None, max_value=None, step=None, format=None): ...203```204205[Components and Configuration](./components-config.md)206207## Global Objects and Utilities208209```python { .api }210# Sidebar access211sidebar: DeltaGenerator212213# Secrets management214secrets: SecretsProxy215216# Version information217__version__: str218219# Configuration220def get_option(key): ...221def set_option(key, value): ...222223# Utility functions224def help(obj): ...225def write(*args, unsafe_allow_html=False): ...226def write_stream(stream, *, help=None): ...227def echo(code_location="above"): ...228```