Hourly Forecasts
Learn how to get hourly weather forecast information for a specific location.
Overview
Hourly forecasts provide the latest weather updates during the day. We can use the endpoints discussed in this lesson to remain up-to-date with the changing weather over the course of the next few hours.
Hourly forecast endpoints
In this lesson, we learn how to retrieve the hourly weather forecast data for a particular location for the next hour, and for a period of the next 12 hours.
1 hour of hourly forecasts
To get hourly forecasts for the next hour, we make a GET
request to the following URL:
http://dataservice.accuweather.com/forecasts/v1/hourly/1hour/{locationKey}
12 hours of hourly forecasts
Similarly, for hourly forecasts for the next 12 hours, we make a GET
request to the following URL:
http://dataservice.accuweather.com/forecasts/v1/hourly/12hour/{locationKey}
Input parameters
The table below shows the list of input parameters for both endpoints.
Parameter | Type | Category | Description |
| string | required | This is our API key. This is a query parameter. |
| integer | required | This is the location’s key. This is a path parameter. |
| string | optional | This is the language in which we have to return the results. Its default value is “en-us.” This is a query parameter. |
| boolean | optional | This is set to "True" to include full details in the response, otherwise it is set to "False." Its default value is "False." This is a query parameter. |
| boolean | optional | This is set to "True" to display metric values in the response, otherwise it is set to "False." It default value is "False." This is a query parameter. |
Sample code
In the code below, we enter 351409
on line 1 as the locationKey
for Seattle, United States.
Note: Please refer to the appendix for a list of some well known cities along with their location keys.
You can try adding some optional parameter(s) on lines 3–4 to fine-tune your results for 1-hour forecasts. You can do the same for 12-hour forecasts on lines 6–7.
Click the "Run" button to see the output.
locationKey = 351409url1Hour = 'http://dataservice.accuweather.com/forecasts/v1/hourly/1hour/' \+ str(locationKey) + '?apikey={{API_KEY}}'url12Hour = 'http://dataservice.accuweather.com/forecasts/v1/hourly/12hour/' \+ str(locationKey) + '?apikey={{API_KEY}}'res1Hour = requests.get(url1Hour)res12Hour = requests.get(url12Hour)printResponse(res1Hour)printResponse(res12Hour)
The code above displays the hourly forecast data for the specified location for the next 1 hour and the next 12 hours. The output includes detailed weather information, including the response parameters given in the table below. In case of failure, an appropriate error message is displayed.
Response parameters
Parameter | Type | Description |
| string | This is the date and time of the forecast. |
| boolean | This indicates whether there is any precipitation or not. |
| boolean | This indicates whether it is daytime or not. |
| object | This provides temperature information. |
| object | This provides “feels like” temperature information. |
| object | This contains wind speed and wind direction values. |
| integer | This provides the humidity value. |
| object | This contains visibility information. |
| string | This is the URL of AccuWeather's website for a detailed forecast. |
| string | This is the URL of AccuWeather's mobile site for a detailed forecast. |
Note: The list of response parameters above is not exhaustive. Please refer to the appendix for details of the response.