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.49.0

index.md docs/

1
# Streamlit
2
3
A faster way to build and share data apps. Streamlit transforms Python scripts into interactive web applications with minimal code, providing a declarative API for creating data dashboards, reports, and chat applications with automatic UI generation, real-time updates, and built-in widgets for user interaction.
4
5
## Package Information
6
7
- **Package Name**: streamlit
8
- **Language**: Python
9
- **Installation**: `pip install streamlit`
10
11
## Core Imports
12
13
```python
14
import streamlit as st
15
```
16
17
## Basic Usage
18
19
```python
20
import streamlit as st
21
import pandas as pd
22
import numpy as np
23
24
# Display text and markdown
25
st.title("My Data App")
26
st.write("Hello, world!")
27
st.markdown("**Bold text** and *italic text*")
28
29
# Display data
30
data = pd.DataFrame({
31
'name': ['Alice', 'Bob', 'Charlie'],
32
'age': [25, 30, 35],
33
'score': [85.5, 92.0, 78.3]
34
})
35
st.dataframe(data)
36
37
# Add interactive widgets
38
name = st.text_input("Enter your name:")
39
age = st.slider("Select your age:", 0, 100, 25)
40
if st.button("Submit"):
41
st.success(f"Hello {name}, you are {age} years old!")
42
43
# Create simple charts
44
chart_data = pd.DataFrame(
45
np.random.randn(20, 3),
46
columns=['a', 'b', 'c']
47
)
48
st.line_chart(chart_data)
49
```
50
51
## Architecture
52
53
Streamlit's architecture centers around the DeltaGenerator pattern:
54
55
- **DeltaGenerator**: Core class that generates UI elements and manages the app's visual tree
56
- **Session State**: Persistent state management across user interactions and app reruns
57
- **Caching System**: Performance optimization through `@st.cache_data` and `@st.cache_resource` decorators
58
- **Widget System**: Automatic state synchronization between UI elements and Python variables
59
- **Rerun Model**: Automatic script re-execution on user interaction, with delta updates to the frontend
60
61
This design enables rapid prototyping while providing the foundation for production-ready data applications, integrating seamlessly with the Python data science ecosystem including pandas, NumPy, matplotlib, Plotly, and hundreds of specialized libraries.
62
63
## Capabilities
64
65
### Display and Content
66
67
Core display functions for text, data, and content rendering including markdown, code, JSON, and media elements.
68
69
```python { .api }
70
def write(*args, unsafe_allow_html=False, **kwargs): ...
71
def markdown(body, unsafe_allow_html=False, help=None): ...
72
def text(body): ...
73
def code(body, language=None, line_numbers=False): ...
74
def json(body): ...
75
def latex(body): ...
76
def html(body, width=None, height=None, scrolling=False): ...
77
def write_stream(stream): ...
78
```
79
80
[Display and Content](./display-content.md)
81
82
### Input Widgets
83
84
Interactive widgets for user input including buttons, text inputs, sliders, selectors, and file uploads.
85
86
```python { .api }
87
def button(label, key=None, help=None, on_click=None, **kwargs): ...
88
def text_input(label, value="", max_chars=None, key=None, **kwargs): ...
89
def slider(label, min_value=None, max_value=None, value=None, **kwargs): ...
90
def selectbox(label, options, index=0, key=None, **kwargs): ...
91
def multiselect(label, options, default=None, key=None, **kwargs): ...
92
def checkbox(label, value=False, key=None, **kwargs): ...
93
def file_uploader(label, type=None, accept_multiple_files=False, **kwargs): ...
94
def chat_input(placeholder="Your message", key=None, max_chars=None, **kwargs): ...
95
def chat_message(name, avatar=None, width="stretch"): ...
96
```
97
98
[Input Widgets](./input-widgets.md)
99
100
### Data Display
101
102
Advanced data display components including interactive dataframes, static tables, and metrics display.
103
104
```python { .api }
105
def dataframe(data=None, width=None, height=None, use_container_width=False, **kwargs): ...
106
def data_editor(data, width=None, height=None, disabled=False, **kwargs): ...
107
def table(data=None): ...
108
def metric(label, value, delta=None, delta_color="normal", **kwargs): ...
109
```
110
111
[Data Display](./data-display.md)
112
113
### Charts and Visualizations
114
115
Built-in charting functions and third-party chart library integrations for data visualization.
116
117
```python { .api }
118
def line_chart(data=None, x=None, y=None, color=None, **kwargs): ...
119
def bar_chart(data=None, x=None, y=None, color=None, **kwargs): ...
120
def area_chart(data=None, x=None, y=None, color=None, **kwargs): ...
121
def scatter_chart(data=None, x=None, y=None, color=None, size=None, **kwargs): ...
122
def plotly_chart(figure_or_data, use_container_width=False, **kwargs): ...
123
def altair_chart(altair_chart, use_container_width=False, **kwargs): ...
124
def pyplot(fig=None, clear_figure=None, **kwargs): ...
125
```
126
127
[Charts and Visualizations](./charts-visualizations.md)
128
129
### Layout and Containers
130
131
Layout management and container elements for organizing app structure including columns, tabs, sidebars, and forms.
132
133
```python { .api }
134
def columns(spec, gap="small"): ...
135
def tabs(tab_labels): ...
136
def container(height=None, border=False): ...
137
def expander(label, expanded=False): ...
138
sidebar: DeltaGenerator
139
def form(key, clear_on_submit=False, border=True): ...
140
def empty(): ...
141
```
142
143
[Layout and Containers](./layout-containers.md)
144
145
### Media and Status
146
147
Media display and status messaging including images, audio, video, and user feedback elements.
148
149
```python { .api }
150
def image(image, caption=None, width=None, **kwargs): ...
151
def audio(data, format="audio/wav", **kwargs): ...
152
def video(data, format="video/mp4", **kwargs): ...
153
def pdf(data, width=None, height=600): ...
154
def success(body, icon=True): ...
155
def error(body, icon=True): ...
156
def warning(body, icon=True): ...
157
def info(body, icon=True): ...
158
def exception(exception): ...
159
def toast(body, icon=None): ...
160
def balloons(): ...
161
def snow(): ...
162
def badge(label, icon=None, color=None): ...
163
def feedback(options, key=None, disabled=False, **kwargs): ...
164
```
165
166
[Media and Status](./media-status.md)
167
168
### State and Caching
169
170
State management, caching mechanisms, and performance optimization tools.
171
172
```python { .api }
173
session_state: SessionStateProxy
174
def cache_data(func=None, *, ttl=None, max_entries=None, **kwargs): ...
175
def cache_resource(func=None, *, ttl=None, max_entries=None, **kwargs): ...
176
```
177
178
[State and Caching](./state-caching.md)
179
180
### Advanced Features
181
182
Advanced functionality including authentication, navigation, fragments, dialogs, and custom components.
183
184
```python { .api }
185
def navigation(pages, position="sidebar"): ...
186
class Page: ...
187
def fragment(func=None, *, run_every=None, **kwargs): ...
188
def dialog(title, *, width="large"): ...
189
def connection(name, type=None, **kwargs): ...
190
def login(user_info_provider=None, **kwargs): ...
191
```
192
193
[Advanced Features](./advanced-features.md)
194
195
### Configuration and Control
196
197
App configuration, execution control, and utility functions.
198
199
```python { .api }
200
def set_page_config(page_title=None, page_icon=None, layout="centered", **kwargs): ...
201
def rerun(): ...
202
def stop(): ...
203
def switch_page(page): ...
204
def get_option(key): ...
205
def set_option(key, value): ...
206
def echo(code_location="above"): ...
207
def help(obj): ...
208
def logo(image, link=None, icon_image=None, size="medium"): ...
209
context: ContextProxy
210
secrets: SecretsProxy
211
```
212
213
[Configuration and Control](./configuration-control.md)