How to have API call on streamlit?

I have built an app using Streamlit to show some graphs. In this app, I am collecting some small data from external source and then plot them. In there any facility by Streamlit to share the raw data using REST API, then others can use data?

1 Like

Sure! You can call an API with any handy library – requests is the most popular choice.

import requests
import streamlit as st

data = requests.get("'https://jsonplaceholder.typicode.com/todos/1'").json()

st.write(data)
4 Likes

Sorry, but what I mean by that was that, how I can use Streamlit as REST API.
In summary, I collect some data from external sources (like what you said) and I plot them by any library. In addition, I want to share these raw data for others(developers or researchers) so, they can analyze data in their own way. I want something like FastAPI to share it among others but I do not know how I can use it alongside Streamlit.

1 Like

Ah, I see. No, there is not currently any way for Streamlit to also provide a REST API, unfortunately. That is definitely something we may consider adding in the future, but it’s not possible currently.

2 Likes

Thank you for this discussion!

FWIW, I also think a REST API would be useful. For example, I’d like to write monitors that check if my streamlit apps are functioning well. So far, I haven’t figured out a way to do this. An API interface would be a great solution for this, and I think it would have lots of other use cases, as well.

2 Likes

+1 on this feature

1 Like

I think this feature is the closest existing request Support custom HTTP requests · Issue #439 · streamlit/streamlit · GitHub – if you’d like to see this prioritized by the dev team, feel free to :+1: that issue

2 Likes

i use the requests library but in the console is downloading and he says is run the app the module is not find !!!