


Data becomes more compelling when it’s interactive. Turning raw numbers into something people can explore in real time transforms insights into experiences. Streamlit makes that shift refreshingly easy, letting you turn Python scripts into browser-based apps with just a few lines of code.
What gives these apps their punch is external data—live information pulled from sources that reflect the world as it moves. APIs bring that possibility into reach. Whether you’re working with weather, stock prices, public health stats, or traffic flow, pulling data live pushes a project from static to situational.
Building Data-Driven Applications with Streamlit and External APIs
This tutorial walks through a lightweight app built in Streamlit that pulls real-time weather data from an external source and visualizes it interactively. It’s a quick, clean way to embed real-world context into your Python workflows.
Why Streamlit + External APIs?
Most data science work happens in notebooks. Great for experimentation, not so great when you need to share it or make it interactive. Streamlit shifts that equation. With almost no setup, you can create sliders, dropdowns, buttons, and charts that run in the browser.


What makes Streamlit even more powerful is the ability to pipe in live data through APIs. With a few lines of code, your app can respond to real-world changes—weather patterns, search trends, financial data—each time someone uses it.
This combination unlocks everything from forecasting tools to live dashboards and decision-making aids. If you’re curious about Streamlit’s broader potential, the official documentation is a solid place to dive deeper.
For this build, we’re using a weather API to demonstrate how easy it is to pull in data on the fly and present it through a simple user interface.
Connecting to a Weather API
To power the app with real-world data, we’re using Visual Crossing’s weather API. It provides access to historical and forecasted conditions across global locations in a developer-friendly format.
Start by signing up for a free account and generating an API key. You’ll use this key to authenticate your requests.
Here’s a basic structure for making a request:
import requests
API_KEY = 'your_api_key_here'
location = 'New York,NY'
url = f'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/{location}?unitGroup=metric&key={API_KEY}&contentType=json'
response = requests.get(url)
data = response.json()
This call returns daily summaries and hourly breakdowns including temperature, humidity, wind speed, and more. Once you’ve got the JSON response, it’s easy to work with in Pandas:
import pandas as pd
days = data['days']
df = pd.DataFrame(days)
print(df.head())
The result is a clean DataFrame with columns like datetime, tempmax, tempmin, humidity, and windspeed. It’s a ready-made feed for visualization or downstream processing.
Building the Streamlit Interface
With the data stream in place, it’s time to design the interface. Streamlit makes it easy to set up an app that accepts user input, triggers an API call, and displays key metrics in real time.
Start with the core layout:
import streamlit as st
st.title("Live Weather Dashboard")
st.write("Enter a city to get the latest weather data.")
Add a city input box and button:
city = st.text_input("City", value="New York")
if st.button("Get Weather"):
# API call and display logic goes here
Keep the code clean by wrapping the API call in a function:
def fetch_weather(city, api_key):
url = f'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline/{city}?unitGroup=metric&key={api_key}&contentType=json'
response = requests.get(url)
return response.json()
Now, when a user submits a city, fetch the data and display weather metrics:
if st.button("Get Weather"):
weather = fetch_weather(city, API_KEY)
current = weather['days'][0]
st.subheader(f"Weather in {city}")
st.metric("Max Temp", f"{current['tempmax']} °C")
st.metric("Min Temp", f"{current['tempmin']} °C")
st.metric("Humidity", f"{current['humidity']}%")
st.metric("Wind Speed", f"{current['windspeed']} km/h")
That’s enough to get a lightweight, responsive app up and running—ready to adapt, scale, and expand.
Data Visualization
Raw metrics are useful, but trends bring them to life. With the weather data stored in a DataFrame, Streamlit makes it easy to turn time-series data into visuals.
Start with your libraries:
import matplotlib.pyplot as plt
import altair as alt
st.line_chart(df[['datetime', 'tempmax', 'tempmin']].set_index('datetime'))
temp_chart = alt.Chart(df).mark_line().encode(
x='datetime:T',
y='tempmax:Q',
tooltip=['datetime', 'tempmax']
).properties(
title='Daily Maximum Temperature'
)
st.altair_chart(temp_chart, use_container_width=True)
humidity_chart = alt.Chart(df).mark_line(color='teal').encode(
x='datetime:T',
y='humidity:Q'
).properties(
title='Daily Humidity Levels'
)
st.altair_chart(humidity_chart, use_container_width=True)
Charts give users an intuitive sense of how the weather is shifting—something numbers alone can’t always convey.


Wrapping Up and Next Steps
You now have a functioning Streamlit app that pulls live weather data, processes it on demand, and presents it through a responsive, browser-based interface. It’s fast to build and easy to adapt—whether you want to add historical context, more metrics, or even predictive models.
This kind of project sits right at the intersection of accessibility and power. Lightweight frameworks are changing how quickly we can turn data into usable tools. If you want to explore this further, take a look at this guide on low-code tools for data science and machine learning projects.
The ability to build with external data in real time isn’t a novelty—it’s becoming a core part of applied data science. Once you learn how to pull, clean, and display external signals, you’re not just analyzing the world. You’re building ways to interact with it.
🌟 Follow Us
💬 I hope you like this post! If you have any questions or want me to write an article on a specific topic, feel free to comment below.


