docs/guides/coming_from/streamlit.md
If you're familiar with Streamlit and looking to transition to marimo, read on.
The biggest difference between Streamlit and marimo is that Streamlit can only be used for data apps, whereas marimo is a notebook-first programming environment that makes it effortless to run notebooks as apps. In addition, marimo is much more performant than streamlit.
Notebook vs. App Framework:
Performance.
File Format:
UI Elements:
Streamlit:
import streamlit as st
st.markdown(
"""
# Greetings
Hello world
"""
)
marimo:
import marimo as mo
mo.md(
"""
# Greetings
Hello world
"""
)
Streamlit:
st.dataframe(df)
marimo:
df # Last expression in a cell is automatically displayed
Streamlit:
age = st.slider("How old are you?", 0, 130, 25)
marimo:
age = mo.ui.slider(label="How old are you?", start=0, stop=130, value=25)
mo.md(f"One more question: {age}") # marimo can achieve more advanced composition
Streamlit:
if st.button("Click me"):
st.write("Button clicked!")
marimo:
button = mo.ui.run_button("Click me")
# In another cell
if button.value:
mo.output.replace(mo.md("Button clicked!"))
# Or
mo.md("Button clicked!") if button.value else None
Streamlit:
col1, col2 = st.columns(2)
with col1:
st.write("Column 1")
with col2:
st.write("Column 2")
marimo:
mo.hstack([
mo.md("Column 1"),
mo.md("Column 2")
])
Streamlit:
with st.expander("Expand me"):
st.write("Hello from the expander!")
marimo:
mo.accordion({"Expand me": "Hello from the expander!"})
marimo's unique approach to composition allows for more flexible layouts with unlimited nesting.
Streamlit:
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1, 2, 3, 4])
st.pyplot(fig)
marimo:
import matplotlib.pyplot as plt
plt.plot([1, 2, 3, 4])
plt.gca() # Last expression is displayed
Streamlit:
@st.cache_data
def expensive_computation(args):
# ...
marimo:
@mo.cache
def expensive_computation(args):
# ...
marimo provides mo.cache and mo.lru_cache for caching function return values, as well as mo.persistent_cache for caching variables to disk.
Streamlit uses st.session_state for persisting data. In marimo, you can use
regular Python variables, as the notebook maintains consistent state for cells
that are not re-executed.
Streamlit:
streamlit run your_app.py
marimo:
marimo run your_notebook.py
value attribute.mo.md() function is versatile and can include both text and UI elements with f-strings.