WeatherStack is one of the most popular real-time & historical world weather data API services on the market. With WeatherStack API, you can instantly retrieve accurate weather information in a lightweight JSON format for any location in the world.
Our weather data API is trusted by 75,000 companies worldwide.
If you have been following our blogs, you know you can find several tutorials about WeatherStack. For instance, this article shows why you should choose WeatherStack for your next project. This article does too.
Table of Contents
What are the benefits of the WeatherStack API?
The Weathewrstack API offers plenty of benefits. Here are a few of them in bullet form:
- Real-Time, History, Forecast
- Millions of Locations
- Rock-Solid Uptime & Speed
- Start Free, Upgrade Later
- Real-Time Weather API
- Historical Weather API
- Weather Forecasts API
- Locations Auto-complete
- Bulk API Endpoint
How do I Get Started with WeatherStack API?
Head over to the WeatherStack subscription page and get your free API access key by registering to the Free/Limited subscription.
How to Utilize WeatherStack API?
The first step to using the API is to authenticate with your WeatherStack unique API access key. You can find it on your account dashboard after you register. To authenticate with the API, use the base URL below and pass your API access key to the API’s “access_key” parameter.
Here is a sample request that you can follow:
1 2 3 |
https://api.weatherstack.com/current ? access_key = YOUR_ACCESS_KEY & query = New York |
Clients using the Standard Plan or higher can connect to the WeatherStack using HTTPS, but you should use the HTTP in the limited or free subscription.
How to get Historical Weather?
To look up historical weather data back to 2008.
1 2 3 4 5 |
https://api.weatherstack.com/historical ? access_key = YOUR_ACCESS_KEY & query = New York & historical_date = 2015-01-21 & hourly = 1 |
How to get a Historical Time-Series?
In addition to looking up historical weather data for specific dates, the API can also process historical time-series results if the parameters historical_date_start and historical_date_end are set to valid dates.
1 2 3 4 5 |
https://api.weatherstack.com/historical ? access_key = YOUR_ACCESS_KEY & query = New York & historical_date_start = 2015-01-21 & historical_date_end = 2015-01-25 |
How to Get Weather Forecast?
WeatherStack can return weather forecast data for up to 14 days into the future. To get it, use the forecast endpoint.
1 2 3 4 5 |
https://api.weatherstack.com/forecast ? access_key = YOUR_ACCESS_KEY & query = New York & forecast_days = 1 & hourly = 1 |
These are not all the features of the WeatherStack API. Be sure to head over and check out all the great functionalities now.
Looking for a comparison between WeatherStack and Open Weather Map?
Check out our comparison article with weatherstack and Open Weather Map.
How to Integrate WeatherStack API?
After you have the API access key you can easily test the endpoints in REST Debugger tools. Follow these commands to initialize a new Python Flask web app.
1 2 3 4 5 6 7 8 |
0. mkdir PythonFlaskDemo 1. cd PythonFlaskDemo 2. touch app.py 3. py -m venv env 4. env\Scripts\activate 5. pip install flask 6. pip install requests 7. set FLASK_APP=app.py |
After these commands, you can manage dependencies for your project in the new Python Flask web app virtual environment. Once done, add this code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
from flask import Flask, request, redirect, url_for import requests app = Flask(__name__) @app.route('/') def hello_world(): # put application's code here return 'Hello World!' @app.route('/result/<string:acc_key>/<string:query>/<string:observation_time>/<string:temperature>/<string:precipitation>/<string' ':humidity>/<string:visibility>') def result_current(acc_key, query, observation_time, temperature, precipitation, humidity, visibility): return "<h3>Query: {}; <br>Observation Time: {}; <br>Temperature: {}; <br> Precipitation: {}; <br> Humidity: {" \ "};<br>Visibility: {};<br>Your Access Key:{} </h3>".format(query, observation_time, temperature, precipitation, humidity, visibility, acc_key) @app.route('/current', methods=['GET', 'POST']) def current(): if request.method == 'GET': return '''<h1>Please fill out the parameters</h1> <form method="POST" action="/current"> <input type="text" name="acc_key"> <input type="text" name="query"> <input type="submit" value="Request"> </form>''' else: acc_key = request.form['acc_key'] query = request.form['query'] req = requests.get('http://api.weatherstack.com/current?access_key=' + acc_key + '&query=' + query) response = req.json() observation_time = response['current']['observation_time'] temperature = response['current']['temperature'] precipitation = response['current']['precip'] humidity = response['current']['humidity'] visibility = response['current']['visibility'] return redirect( url_for('result_current', acc_key=acc_key, query=query, observation_time=observation_time, temperature=temperature, precipitation=precipitation, humidity=humidity, visibility=visibility)) if __name__ == '__main__': app.run() |
Here is our final application in action.
Be sure to head over to WeatherStack.com and get your free API access key right now!