Fastapi backend -> streamlit frontend?

is this the established pattern? new to streamlit. ive made a few dashboards using streamlit behind a nginx ingress basic auth with the data feeds coming from a quick fastapi endpoint. works really well

ive gotta imagine some of you folks are doing the same. any pitfalls i should know about?

love streamlit btw, this shit is dope

This is definitely my preferred solution approach. I usually start off with a Streamlit monolith to get a solution started and to test ideas. I use modular functions which can later be wrapped by FastAPI. Functions that will end up in the server layer should not use any Streamlit APIs, so a little care is required to keep the client UI parts separate from the server parts. The server functions always return literals or dict objects. To mimic st.cache behaviors in the server I use functools/lru_cache or diskcache/memoize. To mimic session state in the server I have a couple of classes and methods that behave the same way as st.session_state. Direct method calls to server functions in the UI tier are then replaced with REST API calls to server functions. As a bonus I often reuse the server functions via a CLI wrapper too, using typer.

However, these kinds of apps can’t be deployed easily to Streamlit Cloud if you wish to access the FastAPI from the external web as well as from the Streamlit app. I have some working code that will do this via Tornado, but it requires an additional mapping layer. I usually deploy these client/server apps in Heroku or another public cloud if local databases are involved.


i see. its fair to say i have no real “experience” with fastapi or streamlit but ive spend two weeks playing with them so i feel well enough experienced.

firstly. again, this shit is dope. i cant believe no one is using this. legit one of the coolest things ive randomly come across.

my deployment model is kinda convoluted but ultimately ive got an nginx basic auth thing going on with some jinja bs that im using to render my app. i saw you page some concept of pages. that seems a more direct route towards modularization

im finding this very intuitive. thank you so much. i feel like this is how i will express myself going forward


I think there are 10s of 1000s of developers using this (Streamlit), but not sure how many in production as those numbers are not available. Maybe the upcoming BUILD event will shed some light on this.

Happy Streamlitin’

1 Like