Spaces:
Sleeping
Sleeping
nav
Browse files- nb/prod_data.py +28 -0
- nb/prod_files.py +28 -0
- nb/prod_home.py +8 -4
- nb/prod_marimo.py +28 -0
- src/main.py +2 -2
- src/marimo_apps.py +30 -8
nb/prod_data.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import marimo
|
| 2 |
+
|
| 3 |
+
__generated_with = "0.18.4"
|
| 4 |
+
app = marimo.App(width="full", app_title="🤩 Data")
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@app.cell
|
| 8 |
+
def _():
|
| 9 |
+
import marimo as mo
|
| 10 |
+
from src.marimo_apps import UI
|
| 11 |
+
|
| 12 |
+
return UI, mo
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@app.cell
|
| 16 |
+
def _(UI, mo):
|
| 17 |
+
md = mo.md("""
|
| 18 |
+
# Yes, Notebooks In Production | PyCon 2026
|
| 19 |
+
|
| 20 |
+
This is a tutorial on building FastAPI+marimo hybrid apps.
|
| 21 |
+
""")
|
| 22 |
+
|
| 23 |
+
mo.hstack([UI.NAV, md], widths=[1, 5])
|
| 24 |
+
return
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
app.run()
|
nb/prod_files.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import marimo
|
| 2 |
+
|
| 3 |
+
__generated_with = "0.18.4"
|
| 4 |
+
app = marimo.App(width="full", app_title="🎁 Files")
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@app.cell
|
| 8 |
+
def _():
|
| 9 |
+
import marimo as mo
|
| 10 |
+
from src.marimo_apps import UI
|
| 11 |
+
|
| 12 |
+
return UI, mo
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@app.cell
|
| 16 |
+
def _(UI, mo):
|
| 17 |
+
md = mo.md("""
|
| 18 |
+
# Yes, Notebooks In Production | PyCon 2026
|
| 19 |
+
|
| 20 |
+
This is a tutorial on building FastAPI+marimo hybrid apps.
|
| 21 |
+
""")
|
| 22 |
+
|
| 23 |
+
mo.hstack([UI.NAV, md], widths=[1, 5])
|
| 24 |
+
return
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
app.run()
|
nb/prod_home.py
CHANGED
|
@@ -1,22 +1,26 @@
|
|
| 1 |
import marimo
|
| 2 |
|
| 3 |
__generated_with = "0.18.4"
|
| 4 |
-
app = marimo.App(width="
|
| 5 |
|
| 6 |
|
| 7 |
@app.cell
|
| 8 |
def _():
|
| 9 |
import marimo as mo
|
| 10 |
-
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
@app.cell
|
| 14 |
-
def _(mo):
|
| 15 |
-
mo.md("""
|
| 16 |
# Yes, Notebooks In Production | PyCon 2026
|
| 17 |
|
| 18 |
This is a tutorial on building FastAPI+marimo hybrid apps.
|
| 19 |
""")
|
|
|
|
|
|
|
| 20 |
return
|
| 21 |
|
| 22 |
|
|
|
|
| 1 |
import marimo
|
| 2 |
|
| 3 |
__generated_with = "0.18.4"
|
| 4 |
+
app = marimo.App(width="full", app_title="🏰 Home")
|
| 5 |
|
| 6 |
|
| 7 |
@app.cell
|
| 8 |
def _():
|
| 9 |
import marimo as mo
|
| 10 |
+
from src.marimo_apps import UI
|
| 11 |
+
|
| 12 |
+
return UI, mo
|
| 13 |
|
| 14 |
|
| 15 |
@app.cell
|
| 16 |
+
def _(UI, mo):
|
| 17 |
+
md = mo.md("""
|
| 18 |
# Yes, Notebooks In Production | PyCon 2026
|
| 19 |
|
| 20 |
This is a tutorial on building FastAPI+marimo hybrid apps.
|
| 21 |
""")
|
| 22 |
+
|
| 23 |
+
mo.hstack([UI.NAV, md], widths=[1, 5])
|
| 24 |
return
|
| 25 |
|
| 26 |
|
nb/prod_marimo.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import marimo
|
| 2 |
+
|
| 3 |
+
__generated_with = "0.18.4"
|
| 4 |
+
app = marimo.App(width="full", app_title="💚 Marimo")
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@app.cell
|
| 8 |
+
def _():
|
| 9 |
+
import marimo as mo
|
| 10 |
+
from src.marimo_apps import UI
|
| 11 |
+
|
| 12 |
+
return UI, mo
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
@app.cell
|
| 16 |
+
def _(UI, mo):
|
| 17 |
+
md = mo.md("""
|
| 18 |
+
# Yes, Notebooks In Production | PyCon 2026
|
| 19 |
+
|
| 20 |
+
This is a tutorial on building FastAPI+marimo hybrid apps.
|
| 21 |
+
""")
|
| 22 |
+
|
| 23 |
+
mo.hstack([UI.NAV, md], widths=[1, 5])
|
| 24 |
+
return
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
if __name__ == "__main__":
|
| 28 |
+
app.run()
|
src/main.py
CHANGED
|
@@ -2,7 +2,7 @@ import typing as t
|
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.responses import RedirectResponse
|
| 4 |
|
| 5 |
-
from .marimo_apps import
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
@@ -17,4 +17,4 @@ def read_item(item_id: int, q: t.Union[str, None] = None):
|
|
| 17 |
return {"item_id": item_id, "q": q}
|
| 18 |
|
| 19 |
|
| 20 |
-
app.mount("/",
|
|
|
|
| 2 |
from fastapi import FastAPI
|
| 3 |
from fastapi.responses import RedirectResponse
|
| 4 |
|
| 5 |
+
from .marimo_apps import marimo_apps
|
| 6 |
|
| 7 |
app = FastAPI()
|
| 8 |
|
|
|
|
| 17 |
return {"item_id": item_id, "q": q}
|
| 18 |
|
| 19 |
|
| 20 |
+
app.mount("/", marimo_apps.build())
|
src/marimo_apps.py
CHANGED
|
@@ -1,4 +1,6 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
| 2 |
from pathlib import Path
|
| 3 |
|
| 4 |
from .log import logger
|
|
@@ -10,14 +12,34 @@ logger.info(f"NB_FOLDER: {NB_FOLDER}")
|
|
| 10 |
|
| 11 |
|
| 12 |
class MarimoApps:
|
| 13 |
-
def __init__(self):
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
def build(self):
|
| 17 |
apps = create_asgi_app(include_code=True)
|
| 18 |
-
for
|
| 19 |
-
|
| 20 |
-
apps = apps.with_app(
|
| 21 |
-
path="/" + file.stem.split("_")[-1], root=file.absolute()
|
| 22 |
-
)
|
| 23 |
return apps.build()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import typing as t
|
| 2 |
+
from collections import OrderedDict
|
| 3 |
+
from marimo import create_asgi_app, nav_menu
|
| 4 |
from pathlib import Path
|
| 5 |
|
| 6 |
from .log import logger
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
class MarimoApps:
|
| 15 |
+
def __init__(self, folder: Path = NB_FOLDER):
|
| 16 |
+
self.folder = folder
|
| 17 |
+
self.files: t.Dict[str, Path] = {}
|
| 18 |
+
for file in self.folder.glob("prod_*.py"):
|
| 19 |
+
logger.debug(f"Mounting Marimo app from: {file}")
|
| 20 |
+
endpoint = "/" + file.stem.split("_")[-1]
|
| 21 |
+
path = file.absolute()
|
| 22 |
+
self.files[endpoint] = path
|
| 23 |
+
|
| 24 |
+
@property
|
| 25 |
+
def pages(self) -> OrderedDict[str, str]:
|
| 26 |
+
_pages = OrderedDict({"/home": "Home"})
|
| 27 |
+
for endpoint in self.files:
|
| 28 |
+
page_name = endpoint[1:].capitalize()
|
| 29 |
+
_pages[endpoint] = page_name
|
| 30 |
+
return _pages
|
| 31 |
|
| 32 |
def build(self):
|
| 33 |
apps = create_asgi_app(include_code=True)
|
| 34 |
+
for endpoint, path in self.files.items():
|
| 35 |
+
apps = apps.with_app(path=endpoint, root=path)
|
|
|
|
|
|
|
|
|
|
| 36 |
return apps.build()
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
marimo_apps = MarimoApps()
|
| 40 |
+
# print(marimo_apps.pages)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class UI:
|
| 44 |
+
TITLE = "Marimo on FastAPI"
|
| 45 |
+
NAV = nav_menu(marimo_apps.pages, orientation="vertical").style(font_size="20px")
|