pypi-streamlit

Description
A faster way to build and share data apps
Author
tessl
Last updated

How to use

npx @tessl/cli registry install tessl/pypi-streamlit@1.50.0

index.md docs/

1
# Streamlit
2
3
A 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.
4
5
## Package Information
6
7
- **Package Name**: streamlit
8
- **Language**: Python
9
- **Installation**: `pip install streamlit`
10
- **CLI Command**: `streamlit run app.py`
11
12
## Core Imports
13
14
```python
15
import streamlit as st
16
```
17
18
## Basic Usage
19
20
```python
21
import streamlit as st
22
import pandas as pd
23
import numpy as np
24
25
# Set page configuration
26
st.set_page_config(
27
page_title="My App",
28
page_icon="🎯",
29
layout="wide"
30
)
31
32
# Display title and text
33
st.title("My Data Dashboard")
34
st.markdown("Welcome to my **Streamlit** app!")
35
36
# Create some sample data
37
data = pd.DataFrame({
38
'x': np.random.randn(100),
39
'y': np.random.randn(100)
40
})
41
42
# Display interactive widgets
43
name = st.text_input("Enter your name:")
44
age = st.slider("Select your age:", 0, 100, 25)
45
show_data = st.checkbox("Show raw data")
46
47
# Display charts and data
48
st.line_chart(data)
49
50
if show_data:
51
st.dataframe(data)
52
53
# Display metrics
54
col1, col2 = st.columns(2)
55
with col1:
56
st.metric("Mean X", f"{data['x'].mean():.2f}")
57
with col2:
58
st.metric("Mean Y", f"{data['y'].mean():.2f}")
59
60
# Create form for user input
61
with st.form("feedback_form"):
62
feedback = st.text_area("Provide feedback:")
63
rating = st.selectbox("Rating:", [1, 2, 3, 4, 5])
64
submitted = st.form_submit_button("Submit")
65
66
if submitted:
67
st.success(f"Thank you {name}! Rating: {rating}/5")
68
```
69
70
## Architecture
71
72
Streamlit follows a reactive programming model built on several key concepts:
73
74
- **Script Re-execution**: The entire script re-runs when user interactions change widget values
75
- **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` decorators
77
- **Delta Generator**: Core abstraction that manages the display tree and updates efficiently
78
- **Widget State**: Automatic state tracking for all input widgets with optional callbacks
79
80
This 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.
81
82
## Capabilities
83
84
### Display Elements
85
86
Core functions for displaying text, data, charts, and media content. Includes everything from simple text and markdown to interactive dataframes and complex visualizations.
87
88
```python { .api }
89
def title(body, anchor=None, *, help=None): ...
90
def header(body, anchor=None, *, help=None, divider=False): ...
91
def markdown(body, *, unsafe_allow_html=False, help=None): ...
92
def dataframe(data, width=None, height=None, *, use_container_width=False, hide_index=None, column_order=None, column_config=None): ...
93
def line_chart(data, *, x=None, y=None, color=None, width=None, height=None, use_container_width=False, help=None): ...
94
def image(image, caption=None, width=None, *, use_column_width=None, clamp=False, channels="RGB", output_format="auto", help=None): ...
95
```
96
97
[Display Elements](./display-elements.md)
98
99
### Input Widgets
100
101
Interactive widgets for user input including buttons, text inputs, selection widgets, file uploads, and form controls.
102
103
```python { .api }
104
def button(label, key=None, help=None, on_click=None, args=None, kwargs=None, *, type="secondary", disabled=False, use_container_width=False, icon=None): ...
105
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"): ...
106
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"): ...
107
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"): ...
108
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"): ...
109
```
110
111
[Input Widgets](./input-widgets.md)
112
113
### Layout and Containers
114
115
Functions for organizing app layout including columns, containers, sidebars, tabs, and expandable sections.
116
117
```python { .api }
118
def columns(spec, *, gap="small"): ...
119
def container(*, height=None, border=None): ...
120
def expander(label, *, expanded=False, icon=None): ...
121
def tabs(tab_list): ...
122
def form(key, *, clear_on_submit=False, border=True): ...
123
```
124
125
[Layout and Containers](./layout-containers.md)
126
127
### State Management
128
129
Session state, query parameters, and context management for maintaining application state across interactions.
130
131
```python { .api }
132
session_state: SessionStateProxy
133
query_params: QueryParamsProxy
134
context: ContextProxy
135
```
136
137
[State Management](./state-management.md)
138
139
### Caching and Performance
140
141
Caching decorators and performance optimization tools for efficient data processing and resource management.
142
143
```python { .api }
144
def cache_data(func=None, *, ttl=None, max_entries=None, show_spinner=True, persist=None, experimental_allow_widgets=False, hash_funcs=None, validate=None): ...
145
def cache_resource(func=None, *, ttl=None, max_entries=None, show_spinner=True, validate=None, hash_funcs=None): ...
146
```
147
148
[Caching and Performance](./caching-performance.md)
149
150
### Navigation and Pages
151
152
Multi-page application support, navigation controls, and execution flow management.
153
154
```python { .api }
155
def set_page_config(page_title=None, page_icon=None, layout="centered", initial_sidebar_state="auto", menu_items=None): ...
156
def navigation(pages, *, position="sidebar", expanded=True): ...
157
class Page: ...
158
def switch_page(page): ...
159
def rerun(): ...
160
def stop(): ...
161
```
162
163
[Navigation and Pages](./navigation-pages.md)
164
165
### User and Authentication
166
167
User authentication, login/logout functionality, and user information access.
168
169
```python { .api }
170
user: UserInfoProxy
171
def login(provider, *, oauth2=None): ...
172
def logout(): ...
173
```
174
175
[User and Authentication](./user-auth.md)
176
177
### Advanced Features
178
179
Chat interfaces, app fragments, modal dialogs, and database connections for sophisticated applications.
180
181
```python { .api }
182
def chat_message(name, *, avatar=None): ...
183
def chat_input(placeholder=None, key=None, max_chars=None, on_submit=None, args=None, kwargs=None, *, disabled=False): ...
184
def fragment(func): ...
185
def dialog(title, *, width="small"): ...
186
def connection(name, type=None, **kwargs): ...
187
```
188
189
[Advanced Features](./advanced-features.md)
190
191
### Components and Configuration
192
193
Custom component framework and column configuration for data editors and dataframes.
194
195
```python { .api }
196
# Custom components
197
components.v1.html(html, *, width=None, height=None, scrolling=False): ...
198
components.v1.declare_component(name, path=None, url=None): ...
199
200
# Column configuration
201
column_config.TextColumn(label=None, width=None, help=None, disabled=None, required=None, default=None, max_chars=None, validate=None): ...
202
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): ...
203
```
204
205
[Components and Configuration](./components-config.md)
206
207
## Global Objects and Utilities
208
209
```python { .api }
210
# Sidebar access
211
sidebar: DeltaGenerator
212
213
# Secrets management
214
secrets: SecretsProxy
215
216
# Version information
217
__version__: str
218
219
# Configuration
220
def get_option(key): ...
221
def set_option(key, value): ...
222
223
# Utility functions
224
def help(obj): ...
225
def write(*args, unsafe_allow_html=False): ...
226
def write_stream(stream, *, help=None): ...
227
def echo(code_location="above"): ...
228
```