How to Make a Weather Dashboard in Python Using OpenWeather API
Learn how to build a real-time weather dashboard using Python and the OpenWeather API. This Python tutorial shows how to fetch and display live weather data!
- Home
- Development Tutorial
- How to Make a Weather Dashboard in Python Using OpenWeather API
Partner With APPECODE! Let’s Work Together!
Let APPECODE implement your vision and take your project from idea to done.
How to Make a Weather Dashboard in Python Using OpenWeather API
This hands-on development tutorial teaches you how to create a weather dashboard using Python and the OpenWeather API. This tutorial is perfect for everyone looking to practice API consumption, data parsing, and simple UI creation. By the end, you’ll have a functional and stylish weather app.
Let’s begin.
Tutorial Information
This tutorial assumes you already have an applicable development environment set up.
In this tutorial, you will create a real-time weather dashboard using Python and the OpenWeather API that allows users to enter a city name and instantly see current weather details like temperature, humidity, and conditions — all displayed either in the console or through an optional basic graphical interface using Tkinter.
Why Use Python and OpenWeather API Together?
Python is an excellent language thanks to its readability, extensive libraries and strong community. Combined with the OpenWeather API — a popular, developer-friendly service providing weather data globally — it’s perfect for building real-time applications. The combination allows you to practice working with APIs, handling JSON, and displaying useful information in a clean interface.
Prerequisites
- Python 3 installed (https://www.python.org/)
- An API key from OpenWeatherMap
- Basic Python knowledge (variables, functions, dictionaries)
- Optional: a simple GUI toolkit like Tkinter or CLI-only
Step 1: Install Required Libraries
Open a terminal and install the requests
library for API calls:
pip install requests
This library will help you make HTTP requests to the OpenWeather API.
Step 2: Set Up Your Python Script
Create a new file named weather_dashboard.py
and add the following starter code:
import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.openweathermap.org/data/2.5/weather"
city = input("Enter city name: ")
params = {
'q': city,
'appid': API_KEY,
'units': 'metric'
}
response = requests.get(BASE_URL, params=params)
data = response.json()
Replace YOUR_API_KEY
with the actual API key from OpenWeather.
Step 3: Parse and Display the Data
Below the existing code, add logic to extract and print relevant data:
if response.status_code == 200:
main = data['main']
weather = data['weather'][0]
print(f"\nWeather in {city}:")
print(f"Temperature: {main['temp']} °C")
print(f"Humidity: {main['humidity']}%")
print(f"Condition: {weather['description'].capitalize()}")
else:
print("Error: Could not retrieve data")
This displays a simple but functional weather report in the console.
Step 4: Improve the Interface
For a basic GUI, you can add Tkinter. Add this to the top of your script:
import tkinter as tk
from tkinter import messagebox
Then create a window and display results using widgets. (This step is optional and can be customized later for a more advanced dashboard.)
Step 5: Final Touches
- Format the output using string formatting
- Handle errors like invalid city names or API key issues
- Style the GUI with labels and buttons if using Tkinter
Conclusion
You’ve just built a simple yet powerful weather dashboard using Python and the OpenWeather API. Whether you stop at the command-line version or build a GUI, this project is great practice for API calls, error handling, and data formatting. You now have a working app that you can expand with forecasts, map views, or historical weather data!
Team APPECODE
This concludes this APPECODE development tutorial. Thanks for coding with us today. You now have the tools and techniques to apply the demonstrated skills in real development scenarios. Whether you’re refining a feature or launching something big, APPECODE is here to guide your technical journey every step of the way. Team APPECODE is all about helping devs like you grow with real-world, hands-on examples. Have questions or project ideas? Let’s keep the conversation going—your next big breakthrough could be one line away.