🌦️ Introduction

In this project, you’ll build a Weather App in Python that retrieves live weather information from an online API.
You’ll learn how to work with HTTP requests, JSON data, and API keys — essential skills for modern developers.
🧠 Key Concepts Covered
| Concept | Description |
|---|---|
| APIs | Application Programming Interfaces — services that let your code talk to other systems. |
| Requests Module | A Python library used to send HTTP requests and receive data. |
| JSON Parsing | Converting JSON data into Python dictionaries for easy handling. |
🧰 What You’ll Need
- Python 3 installed
requestslibrary (install withpip install requests)- Free API key from OpenWeatherMap
💻 Step-by-Step Code
File Name: weather_app.py
import requests
# 🔑 Replace with your own API key
API_KEY = "your_api_key_here"
BASE_URL = "https://api.openweathermap.org/data/2.5/weather"
print("🌤️ Welcome to the Python Weather App!")
city = input("🏙️ Enter city name: ")
# Build full URL with parameters
params = {
"q": city,
"appid": API_KEY,
"units": "metric"
}
response = requests.get(BASE_URL, params=params)
if response.status_code == 200:
data = response.json()
main = data["main"]
weather = data["weather"][0]
print(f"\n📍 City: {data['name']}")
print(f"🌡️ Temperature: {main['temp']}°C")
print(f"💧 Humidity: {main['humidity']}%")
print(f"☁️ Condition: {weather['description'].title()}")
else:
print("⚠️ City not found or API error.")
🧩 Example Output
🌤️ Welcome to the Python Weather App!
🏙️ Enter city name: London
📍 City: London
🌡️ Temperature: 17.5°C
💧 Humidity: 62%
☁️ Condition: Light Rain
🧠 How It Works
- The user inputs a city name.
- Python sends a GET request to the OpenWeatherMap API.
- The app retrieves the JSON response, which includes temperature, humidity, and condition.
- It then displays the data neatly in the console.
⚙️ Improvements You Can Add
- Convert temperature between Celsius and Fahrenheit.
- Display wind speed and pressure.
- Build a GUI version using
tkinter. - Create a daily forecast version with extended API endpoints.
📝 Summary
- You learned how to interact with an external API using Python.
- You practiced JSON parsing and error handling.
- You built a real-time Weather App ready for future improvements.