I am fond of writing Streamlit applications (when a front-end is needed) and fastAPI backends when I just need a REST API.

I've seen many blog posts where these two are combined - with the Streamlit app basically just querying fastAPI endpoints as needed.

But I'm unclear on the benefits? If I am writing a function:

def handle_user_input(user_input):

I could either implement it as fastAPI endpoint and call it from streamlit, or just run this code itself in the streamlit application.

What is the main benefit of maintaining two services instead of one?


Here are some of the blogs I'm referring to:

2 Answers 2


one of the reasons could be the developer does not want to disclose the source codes from the FastAPI app. If you are hardcoding the orginal codes that implement the FastAPI functionalities, anyone visisting the Streamlit app would be able to see the source codes as well. Just a guess, and for your reference. Bests.

  • I see, that's a good answer. I suppose I'm used to building internal tools where the visibility of the implementation logic is not problematic. But I see the benefits.
    – MYK
    Commented Oct 31, 2023 at 12:38

In the last link, it says:

When developing simple APIs that serve machine learning models, it can be useful to have both a backend (with API documentation) for other applications to call and a frontend for users to experiment with the functionality.

That, and the ability to protect your source as suggested by BQ Liu, are plenty of reason for doing this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.