Locations

Other than the type of data (endpoint) itself, the next most important piece of info we need is the location, or place, to which that data pertains. As you get more familiar with the Aeris API, you'll find that in the Aeris API, location and place are sometimes used interchangeably.* For the purpose of the AerisWeather Python SDK, we will use the term "location".

*Even in the requests for the "Places" endpoint - but we'll get to that later...

In the AerisWeather Python library, there a couple of ways to we can pass that location info to the API within a request.

  • the RequestLocation class
  • the "p=" Parameter

The RequestLocation

The RequestLocation class is designed to be flexible enough to handle whatever location information you have, and give the most accurate location info to the API.

To be able to send a valid location to the API, we need either:

latitude and longitude

or

city and state

or

zip/postal code (US and Canada only)

The Aeris Python lib will take the most accurate source of data and pass that to the API. For instance, let's say you create a RequestLocation object, and set the latitude, longitude, city and state like this:


    loc = RequestLocation(city="minneapolis",
    state="mn",
    latitude="44.9778",
    longitude="-93.265")

Then we use that RequestLocation object in an endpoint request, like this:

    obs_list = aeris.observations(location=loc)

When the lib builds the request for the API, it will use the lat and lon, since that's the most accurate of the info given.

If you'd like to dig into the details of the RequestLocation class, check out the code docs, or see some additional examples here.

The "p=" Parameter

In some cases, you may want to use request Actions like "closest" to query the API for data that is closest to the requested place or location.

If we use the p= parameter with an action, it takes the place of the RequestLocation we discussed earlier. For example, we can create a request like this:


    obs_list = aeris.observations(action=RequestAction.OBSERVATIONS.CLOSEST, 
                                  params={ParameterType.OBSERVATIONS.P: "minnneapolis,mn")

Last modified: May 17, 2018