Guide to extract Real time data from Air Visual API.

Anush krishna .V
Voice of Code
Published in
4 min readMay 18, 2020

--

Hello programmers and hackers. If you are new towards how to use API and looking for a way to get started, or wanted to use Air vision API for your application this is the place for you.

What is an API ?

An application programming interface is a computing interface to a software component or a system, that defines how other components or systems can use it. It defines the kinds of calls or requests that can be made, how to make them, the data formats that should be used, the conventions to follow, etc.

What does Air vision API do ?

The community version of the API upon request let’s you return to view your Real time weather and Air quality data . It allows you to make 10k calls a month which is pretty neat for a free to use API .

Here are the Steps you need to follow to Set up and start receiving real time data from this API.

Step 1 — Go to the Air Visual API page.

Click on the link https://www.iqair.com/air-pollution-data-api

You will be greeted by their home page . Click the get started button .

Step 2- Click on Community plan

There are 3 types of plans available, each one having it’s own benefits . The community plan is free and basic . You get the weather and local air quality data . Then you have to click start now .

Step 3- Create an account.

Step 4- Click API Tab.

Step 5-Click on the API tab which will take you to your Dashboard.

The Dashboard presents you with two options keys and Documentation .We will go into Documentation shortly first let’s attain an API key which is very important if you want to use an API.

API-An application programming interface key is a unique identifier used to authenticate a user, developer, or calling program to an API. However, they are typically used to authenticate a project with the API rather than a human user. Different platforms may implement and use API keys in different ways.

Step 6-Click on the +NEW KEY option .

Upon clicking you will be redirected and asked to select a plan . A Community plan will cater all your needs and suggest you start with it before you go and purchase other plans . Select the community plan.

Once you have selected a plan , an API key will be generated and you must copy it . Never share your key with anyone . You have only 10k calls a month so make the best use of it . It will reset the key soon .

Step 7- Copy the KEY.

Step 8 - Click on Documentation.

Documentation will take care of most of your doubts and I strongly recommend that you give it a read .

The code is also readily available. Copy the code and paste in editor and run . You would need good internet connection keep that in mind.

Here is the python code for it . You will need to install Requests module . Do it by:

$ pip3 install requests

import requestsurl = ‘http://api.airvisual.com/v2/nearest_city?key=f7316a56-f7eb-4c55-9b8e-af9877f75d6a'payload = {}files = {}headers= {}response = requests.request(“GET”, url, headers=headers, data = payload, files = files)print(response.text.encode(‘utf8’))

Copy and paste the code and past the API key or Concatenate in the place of “Insert Your API key”.

Hope you find this informative and helpful . If you need any help or have any queries reach out to me in comments or my Twitter handle .

--

--

Anush krishna .V
Voice of Code

MS Data Science @RIT | Ex-Data Engineer @Metabob | Global Finalist IBM CFC | Data Engineering & Science | Looking for an internship