What is the pattern to connect Streamlit UI to backend database

Typically, an application will have three layers. I am new to Streamlit and went through some documentation and a book. However the book only talked about displaying traditional data sources in UI. I am looking for some pointers how I write a Python service behind UI that can call a back-end database and display results.

e.g. Streamlit UI β†’ Services (middle tier) β†’ Database

Can I please get some pointers to an example app either in gallery or documented somewhere?

Thanks

Hi Franky,
these data source examples talk about Streamlit connecting to datasource (or two tier). I am looking for docs that can explain a pattern on how to code a middle tier. For example use FastAPI in between Streamlit and a datasource. Is this not possible with Streamlit?

The usual pattern is that you decide what API you want, then you implement it (using FastAPI or not, that is just an implementation detail) and deploy it.

Now you can call the API from any client that is able to reach your API server, Streamlit shouldn’t make it any different.

Hi,

You may find this example useful: Hybrid architecture media server, media service and Streamlit client app using FastAPI and Python

Cheers,
Arvindra

1 Like

Okay thanks that makes sense. The use case as I could see is two tier rapid web app with Streamlit as front end and a data source as backend. Wanted to make sure if a three tier application is possible for scalability or what ever the reasons.

Do you know if there are applications that employ Streamlit as front end in a three tier app? In gallery or elsewhere.

Right now I can’t thing of any examples in the wild, but see this other reply.

Interesting I posted specific question in that thread. That one is very close to what I am looking for.

I regularly use a remote FastAPI server as a gateway to my business logic which in turn interfaces to a DB (or some persistence mechanism). Streamlit is the UI and calls my FastAPI endpoints for all operations (typically CRUD operations).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.