Create interactive utility app with Streamlit

Streamlit is an open-source Python library that makes it easy to create and share beautiful, custom web apps for machine learning and data science.

Besides data science and machine learning, I found Streamlit can also be used for creating very simple utility apps.

Postboy - a simple Postman-like app

For example, we can create a simple Postman -like app for testing REST APIs with Streamlit in just a few lines of code.

Install Streamlit:

pip install streamlit

Create a file app.py:

import json
import streamlit as st
import requests

st.title("Postboy")

url = st.text_input("URL", "https://jsonplaceholder.typicode.com/posts/1")
method = st.selectbox("Method", ["GET", "POST", "PUT", "DELETE"])

if st.button("Send Request"):
    with st.spinner("Sending..."):
        try:
            response = requests.request(method=method, url=url)
            st.code(json.dumps(response.json(), indent=2), language="json")
        except Exception as e:
            st.write(e)

Run the app:

❯ streamlit run app.py

  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://192.168.0.11:8501

The app will be opened in a browser:

image-20230710232005532

We can further add more features to the app, but the above code demonstrates how easy it is to create a simple utility app with Streamlit.