How can I get my streamlit application to use a flask API in order to retrieve data?

Hello. So I am currently new to working with a flask api and I am just wondering how I can connect a streamlit application to the flask api? Like I would want the streamlit application to be using the flask api that then pulls the database. Currently, my streamlit application is in a folder and it contains a docker file. And I have my flask api in a separate folder.

Main Folder
   Flask-API Folder
      - main.py
      - requirements.txt
      - table1.db
   Streamlit application Folder
      - app.py
      - Dockerfile
      - more python files
      - requirements.txt

For example, if like a user clicked on a check box that produced a graph on streamlit, how can I get the streamlit application to go into the flask-api folder(contact the api) and get/pull the database. I am just wondering what I would have to add to my main.py file in my flask-api folder.

Note: The purpose as to why I am trying to get the streamlit application to contact the flask api is because right now, the streamlit application is contacting another API instead and it takes a while for the graphs to be produced.

Any help is greatly appreciated.

Hi @slee24, welcome to the Streamlit community!

It’s important to separate this problem into “things streamlit does” vs. “other”. In terms of the external API, Streamlit is likely calling that using urllib3 or requests to make HTTP requests. In your design of switching to a Flask app, that should be run outside of Streamlit (in a similar way that the external API you are calling now runs independently of Streamlit on someone else’s server). So in that sense, the way to do this is have a separate Flask process running, and then have your Streamlit app calling that API endpoint with urllib3 or requests.

Best,
Randy

1 Like

Thank you for the input. I was able to resolve this issue with using requests.