Get Current Weather of Any City in Python | Weather App in Python

We made a weather app in vanilla JavaScript. Today we build a weather app in python. In this script, you will get the current weather information of any city.

We use openweathermap to get weather data. openweathermap is a service that provides weather data, including current weather data, forecasts, and historical data to the developers of web services and mobile applications.

Just sign-up yourself in openweathermap and create an account then go to this page: Then generate a key

Now code.


import requests

# paste your api key here
api_key = "4256b3de394a56a86ee35e43af6f5c2e"

# getting city name from user
city = input("Enter city name: ")

we appending the city valirable and api_key variable to complete the url. for example city name is Mumbai  then url looks like
data = requests.get(

# uncomment the following line and run it so you can get the data in json format
# print(data.json())

# getting the data
print(f"Location: {data.json().get('name')}, {data.json().get('sys').get('country')}")
print(f"Temperature: {data.json().get('main')['temp']}°C")
print(f"Weather: {data.json().get('weather')[0].get('main')}")
    f"Min/Max Temperature: {data.json().get('main')['temp_min']}°C/{data.json().get('main')['temp_max']}°C"
print(f"Humidity: {data.json().get('main')['humidity']}%")
print(f"Wind: {data.json().get('wind')['speed']} km/h")

#follow @code_snail on instagram


weather app in python, Find current weather of any city using OpenWeathermap API in Python

Hope you like it this simple weather app in python. Share it with your friends.

Other mini projects,

Leave a Comment

Copy link
Powered by Social Snap