- Spec files
pypi-streamlit
Describes: pkg:pypi/streamlit@1.16.x
- Description
- The fastest way to build and share data apps
- Author
- tessl
- Last updated
index.md docs/
1# Streamlit23Streamlit is a comprehensive Python web application framework that enables developers to rapidly transform data scripts into interactive, shareable web applications. It provides a simple, declarative API for creating rich user interfaces with widgets like sliders, charts, maps, and data tables, all without requiring frontend development knowledge.45## Package Information67- **Package Name**: streamlit8- **Language**: Python9- **Installation**: `pip install streamlit`1011## Core Imports1213```python14import streamlit as st15```1617For custom components:1819```python20import streamlit.components.v1 as components21```2223Type imports for API signatures:2425```python26from typing import Union, List, Dict, Literal, Any, Optional, ContextManager, NoReturn27```2829## Basic Usage3031```python32import streamlit as st33import pandas as pd34import numpy as np3536# Set page configuration37st.set_page_config(38page_title="My App",39page_icon="๐",40layout="wide"41)4243# Create content44st.title("My Streamlit App")45st.write("Welcome to my data application!")4647# Display data48data = pd.DataFrame({49'x': np.random.randn(100),50'y': np.random.randn(100)51})5253st.dataframe(data)54st.line_chart(data)5556# Interactive widgets57name = st.text_input("Enter your name:")58age = st.slider("Select your age:", 0, 100, 25)5960if st.button("Submit"):61st.success(f"Hello {name}, you are {age} years old!")62```6364## Architecture6566Streamlit follows an immediate-mode GUI paradigm where:6768- **Scripts run top-to-bottom** on every user interaction69- **Session state** persists data across reruns70- **Delta Generator** renders UI elements incrementally71- **Caching** optimizes expensive computations72- **Component system** enables custom HTML/JavaScript widgets7374The framework handles the complete web stack including automatic UI generation, real-time updates, WebSocket communication, and deployment capabilities.7576## Capabilities7778### Display Elements and Text7980Core functions for displaying text, data, and status messages including titles, headers, markdown, tables, dataframes, JSON, metrics, and various alert types.8182```python { .api }83def title(body: str, anchor: str = None) -> DeltaGenerator: ...84def header(body: str, anchor: str = None) -> DeltaGenerator: ...85def subheader(body: str, anchor: str = None) -> DeltaGenerator: ...86def text(body: str) -> DeltaGenerator: ...87def markdown(body: str, unsafe_allow_html: bool = False) -> DeltaGenerator: ...88def latex(body: str) -> DeltaGenerator: ...89def code(body: str, language: str = "python") -> DeltaGenerator: ...90def caption(body: str, unsafe_allow_html: bool = False) -> DeltaGenerator: ...91def dataframe(data, width: int = None, height: int = None, use_container_width: bool = False) -> DeltaGenerator: ...92def table(data) -> DeltaGenerator: ...93def json(body) -> DeltaGenerator: ...94def metric(label: str, value, delta=None, delta_color: str = "normal") -> DeltaGenerator: ...95def success(body: str) -> DeltaGenerator: ...96def info(body: str) -> DeltaGenerator: ...97def warning(body: str) -> DeltaGenerator: ...98def error(body: str) -> DeltaGenerator: ...99def exception(exception: Exception) -> DeltaGenerator: ...100```101102[Display Elements and Text](./display-elements.md)103104### Input Widgets105106Interactive form controls for user input including buttons, text fields, sliders, selectors, file uploaders, and specialized inputs like date pickers and color choosers.107108```python { .api }109def button(label: str, key: str = None, help: str = None, on_click=None, args=None, kwargs=None, type: Literal["primary", "secondary"] = "secondary", disabled: bool = False) -> bool: ...110def download_button(label: str, data, file_name: str = None, mime: str = None) -> bool: ...111def checkbox(label: str, value: bool = False, key: str = None) -> bool: ...112def radio(label: str, options, index: int = 0, key: str = None) -> Any: ...113def selectbox(label: str, options, index: int = 0, key: str = None) -> Any: ...114def multiselect(label: str, options, default=None, key: str = None) -> List[Any]: ...115def slider(label: str, min_value=None, max_value=None, value=None, step=None, key: str = None) -> Any: ...116def text_input(label: str, value: str = "", key: str = None, type: str = "default") -> str: ...117def number_input(label: str, min_value=None, max_value=None, value=None, step=None, key: str = None) -> Union[int, float]: ...118def text_area(label: str, value: str = "", height: int = None, key: str = None) -> str: ...119def date_input(label: str, value=None, min_value=None, max_value=None, key: str = None): ...120def time_input(label: str, value=None, key: str = None): ...121def file_uploader(label: str, type=None, accept_multiple_files: bool = False, key: str = None): ...122def camera_input(label: str, key: str = None): ...123def color_picker(label: str, value: str = "#000000", key: str = None) -> str: ...124```125126[Input Widgets](./input-widgets.md)127128### Layout and Containers129130Functions for organizing content including columns, tabs, expandable sections, forms, and container management for creating sophisticated multi-panel layouts.131132```python { .api }133def container() -> DeltaGenerator: ...134def columns(spec) -> List[DeltaGenerator]: ...135def tabs(tab_names: List[str]) -> List[DeltaGenerator]: ...136def expander(label: str, expanded: bool = False) -> DeltaGenerator: ...137def empty() -> DeltaGenerator: ...138def form(key: str) -> DeltaGenerator: ...139def form_submit_button(label: str = "Submit", help: str = None) -> bool: ...140```141142[Layout and Containers](./layout-containers.md)143144### Charts and Media145146Comprehensive visualization and media display capabilities including native chart types, integration with popular plotting libraries, and multimedia content rendering.147148```python { .api }149def line_chart(data=None, x: str = None, y: str = None, width: int = None, height: int = None) -> DeltaGenerator: ...150def area_chart(data=None, x: str = None, y: str = None, width: int = None, height: int = None) -> DeltaGenerator: ...151def bar_chart(data=None, x: str = None, y: str = None, width: int = None, height: int = None) -> DeltaGenerator: ...152def pyplot(fig=None, clear_figure: bool = None) -> DeltaGenerator: ...153def altair_chart(altair_chart, use_container_width: bool = False) -> DeltaGenerator: ...154def vega_lite_chart(spec: dict, use_container_width: bool = False) -> DeltaGenerator: ...155def plotly_chart(figure_or_data, use_container_width: bool = False) -> DeltaGenerator: ...156def bokeh_chart(figure, use_container_width: bool = False) -> DeltaGenerator: ...157def pydeck_chart(pydeck_obj=None, use_container_width: bool = False) -> DeltaGenerator: ...158def graphviz_chart(figure_or_dot: Union[str, graphviz.Graph], use_container_width: bool = False) -> DeltaGenerator: ...159def map(data=None, zoom: int = None, use_container_width: bool = False) -> DeltaGenerator: ...160def image(image, caption: str = None, width: int = None, use_column_width: str = None) -> DeltaGenerator: ...161def audio(data, format: str = "audio/wav", start_time: int = 0) -> DeltaGenerator: ...162def video(data, format: str = "video/mp4", start_time: int = 0) -> DeltaGenerator: ...163```164165[Charts and Media](./charts-media.md)166167### Configuration, Caching, and State Management168169Application configuration, performance optimization through caching decorators, session state management, and utility functions for app lifecycle control.170171```python { .api }172def set_page_config(page_title: str = None, page_icon: str = None, layout: str = "centered", initial_sidebar_state: str = "auto") -> None: ...173def get_option(key: str): ...174def set_option(key: str, value) -> None: ...175@cache176def cached_function(): ...177@experimental_memo178def memo_function(): ...179@experimental_singleton180def singleton_function(): ...181def stop() -> NoReturn: ...182def balloons() -> DeltaGenerator: ...183def snow() -> DeltaGenerator: ...184def progress(value: Union[int, float]) -> DeltaGenerator: ...185def spinner(text: str = "In progress...") -> ContextManager[DeltaGenerator]: ...186def echo(code_location: str = "above") -> ContextManager[DeltaGenerator]: ...187def write(*args, **kwargs) -> DeltaGenerator: ...188def help(obj) -> DeltaGenerator: ...189def experimental_rerun() -> NoReturn: ...190def rerun() -> NoReturn: ...191def experimental_get_query_params() -> Dict[str, List[str]]: ...192def experimental_set_query_params(**query_params) -> None: ...193def experimental_show(*args, **kwargs) -> None: ...194def beta_container() -> DeltaGenerator: ...195def beta_expander(label: str, expanded: bool = False) -> DeltaGenerator: ...196def beta_columns(spec) -> List[DeltaGenerator]: ...197```198199[Configuration and Caching](./caching-config.md)200201### Custom Components202203Framework for creating and using custom HTML/JavaScript components, enabling extension of Streamlit's built-in widget set with reusable interactive elements.204205```python { .api }206def declare_component(name: str, path: str = None, url: str = None) -> ComponentCallable: ...207def html(body: str, width: int = None, height: int = None, scrolling: bool = False) -> None: ...208def iframe(src: str, width: int = None, height: int = None, scrolling: bool = False) -> None: ...209```210211[Custom Components](./custom-components.md)212213## Core Types and Data Structures214215```python { .api }216class DeltaGeneratorProto:217"""Protocol for delta generator objects."""218219class SessionStateProxy:220"""Proxy for session state access."""221def __getitem__(self, key: str) -> Any: ...222def __setitem__(self, key: str, value: Any) -> None: ...223def __contains__(self, key: str) -> bool: ...224def __delitem__(self, key: str) -> None: ...225226class SecretsProxy:227"""Proxy for secrets access."""228def __getitem__(self, key: str) -> Any: ...229def __contains__(self, key: str) -> bool: ...230231class UserInfoProxy:232"""Proxy for user information access (experimental)."""233@property234def email(self) -> str: ...235236# Special variables237session_state: SessionStateProxy238secrets: SecretsProxy239experimental_user: UserInfoProxy240sidebar: DeltaGenerator241```242243## Error Handling244245Streamlit defines several specialized exceptions for different error conditions:246247```python { .api }248class StreamlitAPIException(Exception):249"""Base exception for Streamlit API errors."""250251class NoSessionContext(StreamlitAPIException):252"""Raised when no session context is available."""253254class DuplicateWidgetID(StreamlitAPIException):255"""Raised when duplicate widget keys are used."""256```257258Common error patterns:259- Widget key conflicts raise `DuplicateWidgetID` exceptions260- Missing session context raises `NoSessionContext`261- Invalid configuration values raise `StreamlitAPIException`