# Streamlit

**Streamlit** 是一个开源 Python 框架，用于构建和分享交互式 Web 应用，专注于数据应用、仪表盘和内部工具，无需任何前端代码即可将普通 Python 脚本转化为 Web 应用。<sup>[1](https://github.com/streamlit/streamlit/blob/develop/AGENTS.md)</sup><sup> • </sup><sup>[2](https://www.linkedin.com/company/streamlit)</sup> 它于 2018 年在旧金山创立，自 2022 年起归 [Snowflake](https://www.edgepedia.org/zh/snowflake-inc) 所有。<sup>[2](https://www.linkedin.com/company/streamlit)</sup><sup> • </sup><sup>[3](https://techcrunch.com/2022/03/02/snowflake-acquires-streamlit-for-800m-to-help-customers-build-data-based-apps/?source=mail&trk=article-ssr-frontend-pulse_little-text-block)</sup>

| 关键事实 | 详情 |
|---|---|
| 定位 | 开源（Apache-2.0）Python 库，用于交互式 Web 应用和仪表盘，面向数据应用和内部工具<sup>[1](https://github.com/streamlit/streamlit/blob/develop/AGENTS.md)</sup><sup> • </sup><sup>[4](https://www.modern-datatools.com/compare/streamlit-vs-gradio-vs-dash)</sup> |
| 创立 | 2018 年，旧金山，由 Adrien Treuille、Amanda Kelly 和 Thiago Teixeira 创立<sup>[2](https://www.linkedin.com/company/streamlit)</sup><sup> • </sup><sup>[5](https://www.linkedin.com/posts/chanin-nantasenamat_we-did-it-1-million-streamlit-developers-activity-7435490679000174593-vkoa)</sup> |
| 执行模型 | 每次用户交互时脚本从头到尾重新运行，控件值赋给变量<sup>[6](https://docs.streamlit.io/get-started/fundamentals/main-concepts)</sup> |
| 缓存 | 两个装饰器：`st.cache_data` 用于可序列化数据，`st.cache_resource` 用于机器学习模型和数据库连接等全局资源<sup>[7](https://docs.streamlit.io/develop/concepts/architecture/caching)</sup> |
| 收购 | Snowflake 于 2022 年 3 月 2 日宣布收购，报道金额为 8 亿美元；Snowflake 的文件记录显示收购于 2022 年 3 月 31 日完成，购买对价公允价值为 6.508 亿美元<sup>[3](https://techcrunch.com/2022/03/02/snowflake-acquires-streamlit-for-800m-to-help-customers-build-data-based-apps/?source=mail&trk=article-ssr-frontend-pulse_little-text-block)</sup><sup> • </sup><sup>[8](https://investors.snowflake.com/files/doc_financials/2023/q4/0d4be772-30ac-4017-a78b-a5eaa081840e.pdf)</sup> |
| 最新版本 | 1.65.0 版，发布于 2026 年 10 月 2 日<sup>[9](https://docs.streamlit.io/develop/quick-reference/release-notes)</sup> |
| 采用情况 | Streamlit 宣布达到一百万开发者的里程碑<sup>[10](https://www.linkedin.com/posts/streamlit_one-million-streamlit-developers-activity-7435372806869143552-nISM)</sup> |

## 历史

Streamlit 于 2018 年在旧金山以私有测试版形式成立。一本书记载，创始团队带来了来自 Google X 和自动驾驶初创公司 Zoox 的经验，Streamlit 在获得 600 万美元种子轮融资后于 2019 年 10 月转型为开源框架，随后于 2021 年 4 月完成了由红杉资本领投的 3500 万美元 B 轮融资。<sup>[11](https://www.ebooks2go.com/img/samplefiles/9789349887848_Sample.pdf)</sup> Streamlit 自己的周年纪念文章将联合创始人列为 Adrien Treuille、Amanda Kelly 和 Thiago Teixeira；该书记载的创始人中还包括 Nodira Khoussainova。<sup>[5](https://www.linkedin.com/posts/chanin-nantasenamat_we-did-it-1-million-streamlit-developers-activity-7435490679000174593-vkoa)</sup><sup> • </sup><sup>[11](https://www.ebooks2go.com/img/samplefiles/9789349887848_Sample.pdf)</sup>

2019 年的发布说明显示该框架在那一年初具现代形态：0.36.0 版（2019 年 5 月）引入了 `streamlit run` 服务器架构，单个 Python 会话保持存活，代码重新运行时无需启动新进程；0.43.0 版（2019 年 7 月）增加了交互式控件；0.52.0 版（2019 年 12 月）发布了文件上传控件的预览版。<sup>[12](https://docs.streamlit.io/develop/quick-reference/release-notes/2019)</sup>

2022 年 3 月 2 日，Snowflake 宣布达成收购 Streamlit 的协议；[TechCrunch](https://www.edgepedia.org/zh/techcrunch) 报道交易金额为 8 亿美元。<sup>[3](https://techcrunch.com/2022/03/02/snowflake-acquires-streamlit-for-800m-to-help-customers-build-data-based-apps/?source=mail&trk=article-ssr-frontend-pulse_little-text-block)</sup> Snowflake 的财务文件记录，其于 2022 年 3 月 31 日收购了 Streamlit, Inc. 的全部已发行在外股份，收购日购买对价公允价值为 6.508 亿美元，包括 2.118 亿美元现金和约 190 万股 A 类普通股，后者按每股 229.13 美元的收盘价估值 4.389 亿美元。<sup>[8](https://investors.snowflake.com/files/doc_financials/2023/q4/0d4be772-30ac-4017-a78b-a5eaa081840e.pdf)</sup> Snowflake 表示收购 Streamlit 主要是为了其人才和开发者社区，并将该交易定位为将其平台扩展至由数据科学家和开发者构建的数据应用，无需全栈工程团队。<sup>[8](https://investors.snowflake.com/files/doc_financials/2023/q4/0d4be772-30ac-4017-a78b-a5eaa081840e.pdf)</sup><sup> • </sup><sup>[13](https://www.snowflake.com/en/blog/snowflake-to-acquire-streamlit/)</sup> 2025 年，该项目宣布已达到一百万开发者。<sup>[10](https://www.linkedin.com/posts/streamlit_one-million-streamlit-developers-activity-7435372806869143552-nISM)</sup>

## 执行模型

Streamlit 的标志性行为是全脚本重跑。每当用户与控件交互时，Streamlit 会从头到尾重新运行脚本，将控件的当前状态赋给代码中的变量；滑块移动到位置 10 时，脚本重新运行，`x` 被设为 10。<sup>[6](https://docs.streamlit.io/get-started/fundamentals/main-concepts)</sup> 控件被视为变量：`x = st.slider('x')` 既渲染滑块又返回其值，控件也可以通过字符串键访问。<sup>[6](https://docs.streamlit.io/get-started/fundamentals/main-concepts)</sup> 默认情况下，元素按脚本中出现的顺序从上到下渲染，侧边栏、列、标签页和容器可用于布局。<sup>[14](https://docs.streamlit.io/develop/concepts/design/layouts-and-containers)</sup>

重跑模型产生了两个框架直接解决的问题：长时间运行的函数会在每次交互时再次执行，对象会在每次重跑时重新创建。缓存存储慢速函数调用的结果，使其只运行一次，缓存值可供应用的所有用户使用。<sup>[7](https://docs.streamlit.io/develop/concepts/architecture/caching)</sup> `st.cache_data` 缓存返回可序列化数据（如 DataFrame、数组和 API 响应）的计算，向每个会话返回一份新副本，以防止数据被修改和出现竞态条件；`st.cache_resource` 将全局的、不可序列化的资源（如机器学习模型和数据库连接）缓存为跨所有会话共享的单例。<sup>[7](https://docs.streamlit.io/develop/concepts/architecture/caching)</sup> 两个装饰器都接受 `ttl` 和 `max_entries` 参数以控制缓存时长和大小。<sup>[7](https://docs.streamlit.io/develop/concepts/architecture/caching)</sup> 对于应在重跑之间保留但仅限于单个用户会话的值，Streamlit 提供了会话状态（Session State）。<sup>[7](https://docs.streamlit.io/develop/concepts/architecture/caching)</sup>

控件标识遵循明确规则：控件的标识取决于传递给其命令的参数，提供的 `key` 决定标识；更改无键控件的标签、最小值、最大值、默认值、占位符文本或帮助文本会重置该控件。控件在页面之间不保持状态，未在脚本运行中渲染的控件的数据会被删除，包括其会话状态键值对。<sup>[15](https://docs.streamlit.io/develop/concepts/architecture/widget-behavior)</sup>

## 架构与部署

Streamlit 应用具有客户端-服务器结构。运行 `streamlit run your_app.py` 会启动一个 Python 服务器，为所有用户执行计算，而浏览器前端是客户端；通过网络查看应用时，服务器和客户端运行在不同的机器上。<sup>[16](https://docs.streamlit.io/develop/concepts/architecture/architecture)</sup> 服务器构建在 Tornado Web 框架之上，使用 [WebSocket](https://www.edgepedia.org/zh/websockets) 维持持久的双向通道，每个浏览器标签页或窗口创建自己的会话。<sup>[16](https://docs.streamlit.io/develop/concepts/architecture/architecture)</sup> 应用无法访问用户的文件或操作系统，只能处理通过 `st.file_uploader` 等控件上传的文件。<sup>[16](https://docs.streamlit.io/develop/concepts/architecture/architecture)</sup>

在具有负载均衡或多个服务器副本的部署中，媒体文件的 HTTP 请求不携带会话上下文，可能到达与持有用户 WebSocket 会话的副本不同的副本，从而产生 `MediaFileStorageError: Bad filename` 等错误。文档记载的补救措施包括在代理中启用会话亲和性（粘性）、将媒体转换为通过 WebSocket 传递的 Base64 数据 URI，或将生成的文件存储在 S3 等外部存储中。<sup>[16](https://docs.streamlit.io/develop/concepts/architecture/architecture)</sup>

对于凭据，Streamlit 提供原生的基于文件的 [TOML](https://www.edgepedia.org/zh/toml) 格式密钥管理，在 macOS/Linux 上全局文件位于 `~/.streamlit/secrets.toml`（Windows 上为 `%userprofile%/.streamlit/secrets.toml`），并支持各项目单独的密钥文件；不建议将未加密的密钥存储在 git 仓库中，现有的 dotenv 文件、AWS 凭据文件、Google Cloud Secret Manager 和 HashiCorp Vault 等工具也可使用。<sup>[17](https://docs.streamlit.io/develop/concepts/connections/secrets-management)</sup> 在 Streamlit Community Cloud 上，同样的密钥工作流适用，密钥存储在代码之外。<sup>[18](https://docs.streamlit.io/deploy/concepts/secrets)</sup>

Streamlit Community Cloud 免费托管公共应用。截至 2024 年 2 月，其资源限制约为最低 0.078 核、最高 2 核，最低 690 MB、最高 2.7 GB 内存，以及最高 50 GB 存储；超出限制的应用会被限流或停止运行。<sup>[19](https://docs.streamlit.io/deploy/streamlit-community-cloud/manage-your-app)</sup> Streamlit in Snowflake 在 Snowflake 平台内运行该框架，附加了额外限制，包括阻止外部脚本和样式的内容安全策略，以及在数据仓库运行时上的单会话缓存和显示数据 32 MB 的限制。<sup>[20](https://docs.snowflake.com/en/developer-guide/streamlit/limitations)</sup>

## 在 Python 应用框架中的定位

比较通常将 Streamlit、Gradio 和 Dash 列为三大知名 Python 数据应用框架，其中 Streamlit 与快速原型设计和数据仪表盘相关联，Gradio 与机器学习模型演示相关联，Dash 与生产级企业仪表盘相关联。<sup>[21](https://kindatechnical.com/data-visualization/gradio-vs-streamlit-vs-dash-for-python-data-apps.html)</sup> Streamlit 的响应式模型是变更时全量重跑，而 Gradio 基于事件函数，Dash 使用显式回调，Streamlit 的自定义能力被描述为相比 Dash 的完整 HTML/CSS 控制有限。<sup>[21](https://kindatechnical.com/data-visualization/gradio-vs-streamlit-vs-dash-for-python-data-apps.html)</sup> Streamlit 被定位为更通用的应用构建框架，适合仪表盘、多页应用和内部工具，而 Gradio 用专为机器学习输入输出构建的组件封装单个函数的输入和输出。<sup>[22](https://pythonresources.com/guides/gradio-vs-streamlit/)</sup> 三个框架均免费开源，各自提供付费企业版。<sup>[4](https://www.modern-datatools.com/compare/streamlit-vs-gradio-vs-dash)</sup>

近期版本将该框架扩展至对话式 AI：Streamlit 提供聊天元素 `st.chat_message` 和 `st.chat_input`，用于以纯 Python 构建聊天机器人和 LLM 界面，官方教程涵盖使用 OpenAI 和 [LangChain](https://www.edgepedia.org/zh/langchain) 构建的聊天应用。<sup>[23](https://docs.streamlit.io/develop/tutorials/chat-and-llm-apps)</sup><sup> • </sup><sup>[24](https://docs.streamlit.io/develop/tutorials/chat-and-llm-apps/build-conversational-apps?trk=article-ssr-frontend-pulse_little-text-block)</sup>

## References

1. [streamlit/AGENTS.md, Streamlit GitHub repository](https://github.com/streamlit/streamlit/blob/develop/AGENTS.md)
2. [Streamlit, LinkedIn company page](https://www.linkedin.com/company/streamlit)
3. [Snowflake acquires Streamlit for $800M to help customers build data-based apps, TechCrunch (March 2, 2022)](https://techcrunch.com/2022/03/02/snowflake-acquires-streamlit-for-800m-to-help-customers-build-data-based-apps/?source=mail&trk=article-ssr-frontend-pulse_little-text-block)
4. [Python Data App Frameworks Compared: Streamlit, Gradio, Dash, Modern DataTools](https://www.modern-datatools.com/compare/streamlit-vs-gradio-vs-dash)
5. [Streamlit Reaches 1 Million Developers, Chanin Nantasenamat on LinkedIn](https://www.linkedin.com/posts/chanin-nantasenamat_we-did-it-1-million-streamlit-developers-activity-7435490679000174593-vkoa)
6. [Basic concepts of Streamlit, Streamlit Docs](https://docs.streamlit.io/get-started/fundamentals/main-concepts)
7. [Caching overview, Streamlit Docs](https://docs.streamlit.io/develop/concepts/architecture/caching)
8. [Snowflake Q4 fiscal 2023 financial report, Business Combinations note](https://investors.snowflake.com/files/doc_financials/2023/q4/0d4be772-30ac-4017-a78b-a5eaa081840e.pdf)
9. [Release notes, Streamlit Docs](https://docs.streamlit.io/develop/quick-reference/release-notes)
10. [One million Streamlit developers, Streamlit on LinkedIn](https://www.linkedin.com/posts/streamlit_one-million-streamlit-developers-activity-7435372806869143552-nISM)
11. [Building Data Apps with Streamlit (sample chapter), ebooks2go](https://www.ebooks2go.com/img/samplefiles/9789349887848_Sample.pdf)
12. [2019 release notes, Streamlit Docs](https://docs.streamlit.io/develop/quick-reference/release-notes/2019)
13. [Democratizing Data Apps — Snowflake to Acquire Streamlit, Snowflake blog (March 2, 2022)](https://www.snowflake.com/en/blog/snowflake-to-acquire-streamlit/)
14. [Using layouts and containers, Streamlit Docs](https://docs.streamlit.io/develop/concepts/design/layouts-and-containers)
15. [Widget behavior, Streamlit Docs](https://docs.streamlit.io/develop/concepts/architecture/widget-behavior)
16. [Understanding Streamlit's client-server architecture, Streamlit Docs](https://docs.streamlit.io/develop/concepts/architecture/architecture)
17. [Secrets management, Streamlit Docs](https://docs.streamlit.io/develop/concepts/connections/secrets-management)
18. [Managing secrets when deploying your app, Streamlit Docs](https://docs.streamlit.io/deploy/concepts/secrets)
19. [Manage your app, Streamlit Community Cloud, Streamlit Docs](https://docs.streamlit.io/deploy/streamlit-community-cloud/manage-your-app)
20. [Limitations and library changes, Streamlit in Snowflake, Snowflake Documentation](https://docs.snowflake.com/en/developer-guide/streamlit/limitations)
21. [Gradio vs Streamlit vs Dash for Python Data Apps, kindatechnical.com](https://kindatechnical.com/data-visualization/gradio-vs-streamlit-vs-dash-for-python-data-apps.html)
22. [Gradio vs Streamlit: Which to Use, Python Resources](https://pythonresources.com/guides/gradio-vs-streamlit/)
23. [Build LLM apps, Streamlit Docs](https://docs.streamlit.io/develop/tutorials/chat-and-llm-apps)
24. [Build a basic LLM chat app, Streamlit Docs](https://docs.streamlit.io/develop/tutorials/chat-and-llm-apps/build-conversational-apps?trk=article-ssr-frontend-pulse_little-text-block)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Development tools and collaboration infrastructure › Frameworks, libraries, and APIs › Web frameworks and libraries

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/streamlit

English original: https://www.edgepedia.org/streamlit
