Over the weekend I was wondering if there were any useful APIs out there for retrieving information about the weather for a given location. I was particularly interested in current weather but this post also applies to forecasting. I had a Google and found the OpenWeatherMap service which impressed me for several reasons:
- It is open - anyone can add a weather station to it providing they fulfill certain criteria
- It provides a lot of information related to the weather!
- And most importantly, it is designed with developers in mind.
owm = pyowm.OWM(API_KEY_GOES_HERE)
Then to get the current weather at a given location you need an observation instance which is retrieved from:
observation = owm.weather_at_place("Paris,FR")
An observation contains information about the weather and the location itself, which can be retrieved by observation.get_weather()
and observation.get_location()
respectively.
A weather object contains all the data you could ever need with simple get calls to retrieve specific information, such as:
weather.get_clouds()
weather.get_temperature()
If you’re looking for an easy to use weather API in Python I’d strongly recommend PyOWM. Oh and there’s a simple exe installer available for Windows (as I always have problems with pip
on Windows).