In this blog, I’ll show you how to build a simple weather app in Python. Even if you’re beginner in Python and API things, you’ll understand every single thing, and eventually you’ll know to build this weather app.

This app will ask the user to enter the name of a city, and then it will display the weather information for that city, including temperature, humidity, and weather conditions.
You can simply run this weather app in your terminal or command prompt. It’s perfect for school/college students who are aiming to learn how things work in Python.
What is the real logic behind this Weather APP?
We all know that a Weather APP is a program that takes a valid city name as input from the user and simply shows its weather conditions. But we don’t have the Live Weather Data locally.
So to get this data, we don’t have to collect it ourselves. Instead, we ask a website that already has the weather information. We just use that website and fetch data and this work is done using API.
The Main Logic behind Weather Data: API
API stands for Application Programming Interface.
Just think of it like a waiter in a restaurant.
You (the customer) tell the waiter what you want (your order), and the waiter goes to the kitchen (server) and brings back the food.
In this case, your Weather App in Python is the customer, the API is the waiter, and the weather data is the food. You just need to send a request to the API for the data you want.
We will use a free API from a website called OpenWeatherMap. It gives us the current weather data of any city in the world.
Let’s Create a Weather App in Python Step by Step:
Step 1: Get an API Key from OpenWeatherMap
First, go to https://openweathermap.org/ and create a free account.

After signing up there, go to your profile, and you will find something called an API key which will be required to fetch weather data.
Think of the API key as a secret password. You would just include this key and your code will automatically start fetching the weather data. So, simple.
Step 2: Install the Requests Library
To fetch data from the internet using Python, we use a library called <a href="https://www.geeksforgeeks.org/python/python-requests-tutorial/">requests</a>
.
If you don’t have it installed, open your terminal and type this command:
pip install requests<br>
Step 3: Write the following Python Code in you compilor
Now, open your code editor like VS Code, PyCharm, or even Notepad, and type the following code:
import requests def get_weather(city_name, api_key): base_url = "https://api.openweathermap.org/data/2.5/weather" params = { 'q': city_name, 'appid': api_key, 'units': 'metric' } response = requests.get(base_url, params=params) if response.status_code == 200: data = response.json() city = data['name'] temp = data['main']['temp'] description = data['weather'][0]['description'] humidity = data['main']['humidity'] wind = data['wind']['speed'] print(f"\nWeather in {city}:") print(f"Temperature: {temp}°C") print(f"Condition: {description}") print(f"Humidity: {humidity}%") print(f"Wind Speed: {wind} m/s") else: print("City not found. Please try again.") # Replace with your real API key API_KEY = "your_api_key_here" city_input = input("Enter city name: ") get_weather(city_input, API_KEY)
Let’s understand quickly the code logic:
i) First, we import the requests
library so that we can send a request to the OpenWeatherMap API.
Then we create a function called get_weather()
which takes two inputs, city name and API key.

ii) Using this get_weather() function, we sent a request to the weather website and got back the weather data in something called JSON format.
iii) We then take out the temperature, humidity, weather conditions, and wind speed which we aimed to show on the screen of our weather app in Python.
Important Note: Make sure to replace "your_api_key"
with the real API key you got from the OpenWeatherMap website.
Step 4: Now, Run the Python Code using terminal
First, save the code in a file in your computer, let’s say weather_python_app.py and open your terminal and go to the folder where the file is saved.
Then use this command:
python weather_app.py<br>
The program will ask you to enter a city name, send request, and you’ll see the weather details on your screen.
Congrats Bro! You just built your first real-world app in Python.
Final Words on this Weather App:
Making a weather app is a fun way to learn how APIs work and how to use real-time data. Even though it’s a small project, it teaches you useful things for future big apps. It is one of the most widely famous among python/projects.
Later, you can also make it better by adding buttons and design using Tkinter or saving the weather info in a file.
One thought on “Build a Simple Weather App in Python | Weather Forecast”