This content originally appeared on DEV Community and was authored by Sabin Sim
🌤️ Building a Weather App with Python + Streamlit (Using wttr.in API)
For my next project, I wanted to work with a public API and learn how to fetch external data in Python.
So I built a simple Weather App using wttr.in, which provides weather data without requiring an API key.
This project has two versions:
- Console Version (weather.py)
- Streamlit Web Version (weather_streamlit.py)
This small project helped me learn how to make API requests, handle JSON data, and build a clean UI with Streamlit.
🧱 1. Project Overview
The Weather App allows you to:
- Enter a city name
- Fetch live weather using wttr.in
- View temperature, condition, humidity
- Use it via console or a Streamlit web UI
Simple, clean, and useful — exactly what I want for my Python practice.
📂 Project Structure
weather_app/ │ ├── weather.py # Console version ├── weather_streamlit.py # Streamlit version └── README.md # (optional)
🌐 2. API Used: wttr.in
I chose wttr.in because it:
- Requires no signup
- Returns JSON easily
- Works well for quick projects
🖥️ 3. Console Version (weather.py)
Key features:
- Requests weather using
requestslibrary - Shows temperature, weather description, humidity
- Gracefully handles errors
📌 Code
import requests
city = input("Enter city name: ")
url = f"https://wttr.in/{city}?format=j1"
response = requests.get(url)
if response.status_code != 200:
print("Error fetching weather data.")
exit()
data = response.json()
current = data["current_condition"][0]
print("=== Weather Report ===")
print("City:", city)
print("Temperature:", current["temp_C"], "°C")
print("Weather:", current["weatherDesc"][0]["value"])
print("Humidity:", current["humidity"], "%")
🌤️ 4. Streamlit Web Version (weather_streamlit.py)
Why Streamlit?
Because Streamlit turns Python scripts into fast, interactive web apps — perfect for tools like this.
Added features:
- Clean web UI
- User-friendly city input
- Error messages
- Styled weather data output
📌 Code
import streamlit as st
import requests
st.title("🌤️ Sabin's Weather App")
city = st.text_input("Enter city name:", "Chur")
if st.button("Check Weather"):
url = f"https://wttr.in/{city}?format=j1"
response = requests.get(url)
if response.status_code != 200:
st.error("Error fetching weather data.")
else:
data = response.json()
current = data["current_condition"][0]
temp = current["temp_C"]
desc = current["weatherDesc"][0]["value"]
humidity = current["humidity"]
st.subheader(f"Weather in {city}")
st.write(f"🌡 Temperature: <strong>{temp}°C</strong>", unsafe_allow_html=True)
st.write(f"☁ Condition: <strong>{desc}</strong>", unsafe_allow_html=True)
st.write(f"💧 Humidity: <strong>{humidity}%</strong>", unsafe_allow_html=True)
python
⚙️ 5. How to Run
✔ Console Version
python3 weather.py
✔ Streamlit Version
pip install streamlit
streamlit run weather_streamlit.py
Streamlit will automatically open a browser window for the web UI.
📚 6. What I Learned
- How to make API requests with
requests - How to parse JSON responses
- How to build an interactive UI with Streamlit
- Error handling for network responses
- How to convert a console script into a web app
🔧 7. Future Improvements
- Add weather icons
- Show hourly + weekly forecast
- Support multiple languages
- Add background theme (sunny, cloudy, rainy)
- Allow saving favorite cities
This content originally appeared on DEV Community and was authored by Sabin Sim
Sabin Sim | Sciencx (2025-11-30T22:26:32+00:00) My Project 3: Building a Weather App with Python + Streamlit. Retrieved from https://www.scien.cx/2025/11/30/my-project-3-building-a-weather-app-with-python-streamlit/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.