AccuWeather API Python Code

Here is a quick and dirty snippet of Python code to get you started with the AccuWeather API. Note that it offers no fault tolerance, optimization, or other things you might expect to find in finished software and only extracts a small subset of the data available in the JSON data.

import json
import time
import urllib.request


def get_weather(api, location_id):
    url = '' % (location_id, api)
    with urllib.request.urlopen(url) as url:
        data = json.loads(
    return (data[0]['Temperature']['Imperial']['Value'],

timestamp = time.time()

temperature, humidity, wind_bearing, wind_speed, uv_index, cloud_cover, pressure, precipitation, raw \
    = get_weather(API, LOCATION_ID)


AccuWeather API

First up in my series on weather APIs is the one from AccuWeather.

There are a few really great things about this API–or rather this set of APIs–but first let me tell you about the downsides. Accuweather doesn’t use a standardized system for locations so, as far as I can tell, there isn’t a way to simply input Lat/Lon coordinates. Instead your first stop on any journey has to be with their location finding API. Not only is this counter-intuitive, but since they only provide 40 free hits to their API a day, having to make regular checks for different locations could quickly eat up your allotment. Furthermore since forecast, current conditions, and indexes are all separate APIs, you are likely to be making a lot more calls than you would with a service like Darksky. I don’t mean to complain–after all they do offer access for free and 40 API calls is more than enough for the average hobbyist–but it seems stingy in comparison to most other services.

On the other hand, the API provides a superb data set that is easy to navigate and is clearly described in their documentation. Just take a look at their current conditions API¬†which is well documented and includes all sorts of numbers that I didn’t even know were things–honestly did you know what “wet bulb temperature” was before reading that page? Similarly the forecast API¬†offers things like pollen and air pollution information which must APIs lack.

Importantly AccuWeather does not suffer from the “disappearing metric” problem which plagues many APIs–more on this later.

The AccuWeather API may be right for you if your needs are limited to a single location and only a few updates a day. But if your location needs are more complex or want minute-by-minute updates. Also I think that AccuWeather only outputs to JSON, so if you are an XML head you are out of luck. For my particular use–graphing weather data for general interest and to compare to internal sensor data–AccuWeather works well and may come the closest to being an all-in-one solution. I just really wish that they supported more options for location input.

In my next post, I will share some example Python code which will show you how easy it is to get up and running with this API.


Evaluating Weather APIs

Many Internet-of-Things applications require knowledge of various environmental factors such as temperature, humidity, and light levels. While various sensors exist that fill this need locally–such as the ubiquitous DHT11/22 temperature and humidity sensor–sometimes an application requires broader weather data or just a sense of whether or not it is raining outside. Other applications might benefit from weather forecasts.

Thankfully the Internet provides us hobbyists and makers with a ton of APIs that provide weather data. Honestly the sheer volume of the APIs can be overwhelming. For a project that I’ve been playing around with–an indoor environmental monitoring system–I wanted some external data for comparison and worked with quite a few different APIs before I found the mix that worked for me. In the next few posts I’ll share my experiences and some sample code for working with each one.

But first here is a look at the contenders I will be evaluating

As a preview I’ve found that each has their pluses and minuses. Some provide lots of information, but have quirks in their API that make them annoying to use. Others lack data that seems essential. Ultimately–as I have cycles and bandwidth to spare–I combined all four in my final solution.