@whitphx
...and more and more 👉 https://streamlit.io/components
pip install stmol
pip install streamlit-drawable-canvas
...and more and more 👉 https://streamlit.io/components
pip install stmol
pip install streamlit-drawable-canvas
streamlit run app.py
import streamlit as st
st.title("Hello World!")
name = st.text_input("What's your name?")
st.write(f"Hello, {name}!")
app.py
streamlit run app.py
import streamlit as st
st.title("Hello World!")
name = st.text_input("What's your name?")
st.write(f"Hello, {name}!")
app.py
📜
app.py
Web browser
JS runtime
streamlit run app.py
Python runtime
Streamlit
Server
Script runner
🌪️Web server
Static files
JS app
Render
Trigger events
Because it serves web pages from a web server,
and runs Python scripts on the server to process input data,
it lacks...
...and for service developers,
are also sometimes problems.
stlite is a fork of Streamlit
that runs completely on web browsers.
Pyodide is a Python distribution
for the browser and Node.js
based on WebAssembly.
📜
app.py
Web browser
JS runtime
streamlit run app.py
Python runtime
Streamlit
Server
Script runner
🌪️Web server
Static files
JS app
Render
Trigger events
📜
app.py
Web browser
JS runtime
Pyodide runtime
(Wasm CPython)
Streamlit
Worker
Script runner
Static files
JS app
Render
Trigger events
Web
Desktop
Mobile
<!DOCTYPE html>
<html>
<head>
<title>stlite app</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@stlite/mountable@0.26.0/build/stlite.css"
/>
</head>
<body>
<div id="root"></div>
<script src="https://cdn.jsdelivr.net/npm/@stlite/mountable@0.26.0/build/stlite.js"></script>
<script>
stlite.mount(
`
import streamlit as st
name = st.text_input('Your name')
st.write("Hello,", name or "world")
`,
document.getElementById("root")
);
</script>
</body>
</html>
👈 Please ⭐️
@whitphx
👈 Send feature requests and bug reports!
Pyodide runs in the web browser environment.
import asyncio
import streamlit as st
async def main():
await asyncio.sleep(1)
st.title("Hello World!")
asyncio.run(main())
In the browser/Node environment,
the async features rely on the JS runtime.
There is only single running event loop.
import asyncio
import streamlit as st
st.title("Hello world!")
await asyncio.sleep(1)
st.title("Goodbye, world!")
import time
import streamlit as st
st.title("Hello world!")
time.sleep(1)
st.title("Goodbye, world!")
import asyncio
import streamlit as st
st.title("Hello world!")
await asyncio.sleep(1)
st.title("Goodbye, world!")
On Pyodide, time.sleep() is no op.
✅
🚫
On Pyodide, urllib and requests do not work.
> Why can’t I just use urllib or requests?
> We currently can’t use such packages since sockets are not available in Pyodide.
> https://pyodide.org/en/stable/usage/faq.html#how-can-i-load-external-files-in-pyodide
import urllib.request
res = urllib.request.urlopen("...")
import pyodide.http
res = await pyodide.http.pyfetch("...")
✅
🚫
Browser environment
Pyodide
Virtual File System (Emscripten FIle System)
Streamlit
📜
app.py
open()
stlite.mount(
{
entrypoint: "👋_Hello.py",
files: {
"👋_Hello.py": `
import streamlit as st
st.set_page_config(page_title="Hello")
st.title("Main page")
`,
"pages/1_⭐️_Page1.py": `
import streamlit as st
st.set_page_config(page_title="Page1")
st.title("Page 1")
`,
"pages/2_🎈_Page2.py": `
import streamlit as st
st.set_page_config(page_title="Page2")
st.title("Page 2")
`,
},
},
document.getElementById("root")
);
We keep the original Streamlit's API as much as possible.
📜
app.py
Web browser
JS runtime
Pyodide runtime
(Wasm CPython)
Streamlit
Worker
Script runner
Static files
JS app
Render
Trigger events
... the package has binary extensions (e.g. C, Fortran or Rust), in which case it needs to be packaged in Pyodide.
34 new packages have been added in Pyodide 0.21 release, including a large number of popular packages, for example bitarray, opencv-python, shapely, and xgboost.
import pyodide.http
res = await pyodide.http.pyfetch("https://streamlit.io")
Streamlit (Snowflake)
Databutton
Hal9
Hugging Face
Jeremy Tuloup, "JupyterLite: Jupyter ❤️ WebAssembly ❤️ Python", PyConDE & PyData Berlin 2022.
PyScript
Shinylive
HoloViz Panel
stlite