nellyg
nellyg8mo ago

FastAPI deployment

I am trying to replace some apps at my company with some marimo apps. I am looking for some solid comprehensive examples of how to launch marimo with fast api that is a little more in depth than the ~20 lines of code in the docs. Does anyone know if I can find this somewhere?
15 Replies
Akshay
Akshay8mo ago
Not sure if we have a complete example yet. But @Myles Scolnick should be able to help!
Myles Scolnick
Myles Scolnick8mo ago
hey @nellyg what exactly is missing that you want more in depth on? There are docs here: https://docs.marimo.io/guides/deploying/programmatically.html#fastapi-example There is a working example here: https://github.com/marimo-team/marimo/blob/ms/export-markdown/marimo/_smoke_tests/custom_server/my_server.py#L9 I'm hesitant to add more in-depth fastapi knowledge when their docs are really good and in-depth. assuming you are looking for authN, authZ, sessions, etc, I would reference fastapi's docs: https://fastapi.tiangolo.com/
nellyg
nellygOP8mo ago
Oh this working example is exactly what I was looking for. THanks! @Myles Scolnick any suggestions on a good way to give a multi page marimo application a sidebar to navigate between the different pages?
Myles Scolnick
Myles Scolnick8mo ago
how custom is your sidebar? if you could, would you want to build it in marimo or do you want to write your own frontend for that? (e.g. login/logout, special styling, etc)
nellyg
nellygOP8mo ago
I would prefer to build it in Marimo. Really all I want is it to be a list of the pages in my app you can navigate to. Something just like: Button for Homepage Button for Dashboard 1 Button for Dashboard 2 All I am looking for is a really simple way to navigate from any app page to any other app page.
Myles Scolnick
Myles Scolnick8mo ago
gotcha - we plan to make this much easier in the future with some page layouts and routing components. but you could do this today with some cell composition. you can create a notebook called common.py which is just an mo.hstack and mo.md inside with links (we plan to build navigation-items as a component) then in each app, you can import:
from common import sidebar

output, definitions = sidebar.run()
mo.hstack([output, rest_of_application])
from common import sidebar

output, definitions = sidebar.run()
mo.hstack([output, rest_of_application])
i would maybe use vstack and have your navigation at the top just since we don't have good sidebar layouting, but eventually we will have mo.page or something like that to import a cell from another notebook, you need to name your cell, which can be found in the cell action menu
nellyg
nellygOP8mo ago
Okay awesome I will start here and see what I come up with. Thanks for a push in the right direction! Any idea how long some of these built in components might be? If they are coming pretty fast I may hold off. I think really the routing components would be the most helpful. I can get by with creating my own ad hoc top navigation widget.
Myles Scolnick
Myles Scolnick8mo ago
Maybe a week? Also if there are any particular non-obvious requirements like query params or nested paths, let me know
nellyg
nellygOP8mo ago
Oh just a week? Ill just sit tight then. That is fantastic. You guys are so awesome and fast
Myles Scolnick
Myles Scolnick8mo ago
@nellyg - just released mo.nav_menu in the 0.5.1 - its barebones but should unblock you
nellyg
nellygOP8mo ago
Amazing. I will take a look at this tomorrow! Couldn't wait till tomorrow. I got back on to mess with it a bit tonight. This is exactly what I needed to unblock me.
Myles Scolnick
Myles Scolnick8mo ago
awesome to hear
nellyg
nellygOP8mo ago
@Myles Scolnick follow up on this. I just rebuilt a whole panel application into marimo in about 24 hours and it is so much better now and easier to use. Marimo is now my go to notebook and data application framework. I love it
Myles Scolnick
Myles Scolnick8mo ago
That’s amazing You’re gonna hate me though… I’m just adding mo.sidebar Although should actually be a good addition and will fit in nicely
nellyg
nellygOP8mo ago
Nothing at all to hate about that! Im sure I’ll add it to my application within 30 minutes of the release!