My Project 3: Building a Weather App with Python + Streamlit

Published: (November 30, 2025 at 05:26 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

1. Project Overview

  • Enter a city name
  • Fetch live weather using wttr.in
  • View temperature, condition, humidity
  • Available as a console script (weather.py) or a Streamlit web UI (weather_streamlit.py)

Simple, clean, and useful — perfect for Python practice.

2. API Used: wttr.in

wttr.in was chosen because it:

  • Requires no signup
  • Returns JSON easily
  • Works well for quick projects

3. Console Version (weather.py)

Key Features

  • Requests weather using the requests library
  • Shows temperature, weather description, and 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?

  • Clean web UI
  • User‑friendly city input
  • Clear 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: **{temp}°C**", unsafe_allow_html=True)
        st.write(f"☁ Condition: **{desc}**", unsafe_allow_html=True)
        st.write(f"💧 Humidity: **{humidity}%**", unsafe_allow_html=True)

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

  • Making API requests with requests
  • Parsing JSON responses
  • Building an interactive UI with Streamlit
  • Error handling for network responses
  • Converting a console script into a web app

7. Future Improvements

  • Add weather icons
  • Show hourly + weekly forecast
  • Support multiple languages
  • Add background themes (sunny, cloudy, rainy)
  • Allow saving favorite cities
Back to Blog

Related posts

Read more »

Day 1276 : Career Climbing

Saturday Before heading to the station, I did some coding on my current side project. Made some pretty good progress and then it was time to head out. Made i...

JWT Token Validator Challenge

Overview In 2019 Django’s session management framework contained a subtle but catastrophic vulnerability CVE‑2019‑11358. The framework failed to properly inv...