It’s an exciting time to be working in the loft studios of AerisWeather development. The powerful AerisWeather Mapping Platform has become a leading weather map service. Our radar coverage has expanded to new areas of the globe like Australia and South Korea. WeatherBlox, the service that enables web devs to easily add weather content to their sites are always adding new “blox”. We’re constantly pushing updates to the iOS and Android toolkits to keep them up to date with the fast-moving mobile scene.
Here at AerisWeather we sometimes say “the weather never sleeps”, and for the toolkit team that means there are always more ways to help our customers utilize the weather data they need. So without further adieu, we’re very excited to introduce the newest member of the toolkit lineup: The AerisWeather Python SDK!
The AerisWeather Python SDK is the latest coding toolkit from AerisWeather. As with all of our toolkits, the goal is to make it easier to get weather data from our API into your project. While working towards that goal with the Python SDK, we did our best to also make it as “Pythonic” as possible. A couple of our favorite concepts of Python (from the Zen of Python
– PEP20) are:
Don’t have an active AerisWeather API client account? You can sign up for a free developer trial.
Let’s check out an example using the AerisWeather Python library. In the following code snippet, we’ll create an aerisweather object and do a simple observations request:
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 |
from aerisweather.aerisweather import AerisWeather from aerisweather.requests.RequestLocation import RequestLocation from keys import client_id, client_secret, app_id # instantiate our aerisweather object aeris = AerisWeather(client_id=client_id, client_secret=client_secret, app_id=app_id) # create a RequestLocation object to be used with any endpoint requests loc = RequestLocation(city="minneapolis", state="mn") # create a simple observations request with no options obs_list = aeris.observations(location=loc) for obs in obs_list: # get the AerisPlace responses object place = obs.place # get the observations data object ob = obs.ob # get some observations data tempF = ob.tempF weather = ob.weather print("Simple Observations Request Example:") print("The current weather for " + place.name + ", " + place.state + ":") print("Conditions are currently " + weather + " with a temp of " + str(tempF) + "°F") |
Easy, right? That’s all there is to it! Here’s a little more complex request, this time it’s to the forecasts endpoint with some optimization so that we only receive the data we need from the API:
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 |
from aerisweather.aerisweather import AerisWeather from aerisweather.requests.ParameterType import ParameterType from aerisweather.requests.RequestLocation import RequestLocation from aerisweather.requests.RequestAction import RequestAction from aerisweather.requests.RequestFilter import RequestFilter from keys import client_id, client_secret, app_id # instantiate our aerisweather object aeris = AerisWeather(client_id=client_id, client_secret=client_secret, app_id=app_id) # Let's create a new RequestLocation, this time using a postal code loc = RequestLocation(postal_code="55124") # we'll limit the fields returned by the API too, to just the ones we need for our example forecast_list = aeris.forecasts(location=loc, params={ParameterType.FORECASTS.FIELDS: "periods.isDay, periods.maxTempF, periods.minTempF, periods.weather"}) for forecast in forecast_list: # check to see if this is a day or night forecast if forecast.periods[0].isDay: day = forecast.periods[0] night = forecast.periods[1] else: day = forecast.periods[1] night = forecast.periods[0] print("Forecast Example:") print("Today expect " + day.weather + " with a high temp of " + str(day.maxTempF) + "°") print("Tonight will be " + night.weather + " with a low temp of " + str(night.minTempF) + "°") |
Of course, these are just simple examples, so for more details and real-life examples check out the AerisWeather Python SDK homepage. There you’ll find information on how to set up your project, a walkthrough of the basic concepts and lots more. We have topics that cover doing custom data requests, batch requests and examples of it all.
Thanks for checking out the AerisWeather Python SDK. We hope you find it useful, and enjoy using it as much as we enjoyed creating it!
The AerisWeather Python Team
No comments yet.
Be the first to respond to this article.