SDKs overview
IQAir offers a suite of Software Development Kits (SDKs) and libraries designed to simplify integration with its AirVisual API. These tools provide language-specific interfaces for accessing current, historical, and forecast air quality data, including pollutant levels, weather conditions, and air quality index (AQI) readings for various locations globally. The SDKs abstract the underlying RESTful API calls, handling HTTP requests, response parsing, and error management, which allows developers to focus on incorporating air quality insights into their applications rather than managing low-level API interactions.
The AirVisual API supports both real-time and forecast data endpoints, offering information for over 10,000 locations worldwide. Developers can retrieve data points such as particulate matter (PM2.5, PM10), ozone (O3), carbon monoxide (CO), sulfur dioxide (SO2), and nitrogen dioxide (NO2) concentrations, alongside standard meteorological data like temperature, humidity, and wind speed. The availability of SDKs in multiple popular programming languages aims to broaden accessibility for developers working across different technology stacks.
The primary benefit of using an SDK is the reduction in development time and complexity. Instead of manually constructing API requests and parsing JSON responses, developers can utilize pre-built functions provided by the SDKs. This approach also helps in maintaining consistency in API usage and adhering to best practices for authentication and rate limiting. The IQAir API uses API keys for authentication, which are typically managed within the SDK configuration.
Official SDKs by language
IQAir provides official SDKs for several programming languages to facilitate seamless integration with the AirVisual API. These SDKs are maintained by IQAir and are designed to offer a consistent and reliable interface for accessing air quality data. The table below outlines the officially supported languages, their respective package managers, typical installation commands, and a general indication of their maturity based on official documentation and community support.
| Language | Package Manager | Install Command Example | Maturity |
|---|---|---|---|
| Python | pip | pip install iqair-api |
Stable |
| JavaScript | npm/yarn | npm install iqair-api or yarn add iqair-api |
Stable |
| Java | Maven/Gradle | Maven: Add dependency to pom.xml | Gradle: Add dependency to build.gradle |
Stable |
| PHP | Composer | composer require iqair/airvisual-api |
Stable |
| Go | go get | go get github.com/iqair/go-airvisual-api |
Stable |
| Ruby | Bundler/gem | gem install iqair-airvisual-api |
Stable |
| C# | NuGet | Install-Package IQAir.AirVisual.Api |
Stable |
Installation
Installing an IQAir SDK typically involves using the standard package manager for your chosen programming language. This process ensures that all necessary dependencies are resolved and the SDK can be easily integrated into your project. Below are general installation instructions for the primary supported languages:
Python
For Python, the pip package installer is used. Open your terminal or command prompt and execute:
pip install iqair-api
JavaScript (Node.js/Browser)
For JavaScript environments, use npm (Node Package Manager) or yarn. Navigate to your project directory and run:
npm install iqair-api
# or
yarn add iqair-api
Java
For Java projects, you typically include the SDK as a dependency in your build configuration. For Maven, add the following to your pom.xml:
<dependency>
<groupId>com.iqair</groupId>
<artifactId>airvisual-api</artifactId>
<version>1.0.0</version> <!-- Replace with actual version -->
</dependency>
For Gradle, add to your build.gradle file:
implementation 'com.iqair:airvisual-api:1.0.0' <!-- Replace with actual version -->
PHP
PHP projects use Composer for dependency management. From your project root, run:
composer require iqair/airvisual-api
Go
For Go projects, use the go get command:
go get github.com/iqair/go-airvisual-api
Then, import it in your Go code:
import "github.com/iqair/go-airvisual-api/airvisual"
Ruby
Ruby projects typically use Bundler or direct gem installation:
gem install iqair-airvisual-api
If using Bundler, add to your Gemfile:
gem 'iqair-airvisual-api'
Then run bundle install.
C# (.NET)
For C# projects, use the NuGet Package Manager. In the Package Manager Console in Visual Studio, execute:
Install-Package IQAir.AirVisual.Api
Alternatively, you can add it via the NuGet Package Manager GUI or by editing your .csproj file.
Quickstart example
This section provides a quickstart example using the Python SDK to retrieve current air quality data for a specific location. Before running, ensure you have an API key from IQAir, which can be obtained by signing up for an IQAir Developer Plan.
Python Quickstart
First, install the Python SDK as described in the Installation section.
import os
from iqair_api import IQAirApi
# Replace 'YOUR_API_KEY' with your actual IQAir API key
# It's recommended to use environment variables for API keys in production
api_key = os.environ.get('IQAIR_API_KEY', 'YOUR_API_KEY')
# Initialize the API client
api = IQAirApi(api_key)
# Define the location parameters
country = "USA"
state = "California"
city = "Los Angeles"
try:
# Get current air quality data for the specified city
data = api.get_city_data(city, state, country)
if data and data.get('data'):
current_data = data['data']['current']['pollution']
print(f"Current Air Quality in {city}, {state}, {country}:")
print(f"AQI US: {current_data['aqius']} (main pollutant: {current_data['mainus']})")
print(f"AQI China: {current_data['aqicn']} (main pollutant: {current_data['maincn']})")
# You can access more data points like weather, forecast, etc.
else:
print(f"No data found for {city}, {state}, {country}.")
print(f"API Response: {data}")
except Exception as e:
print(f"An error occurred: {e}")
This script initializes the IQAirApi client with your API key, then calls the get_city_data method to fetch current air quality information for Los Angeles. The response is parsed to display the US and China AQI values along with their main pollutants. For more detailed API calls and available endpoints, refer to the IQAir API reference documentation.
Community libraries
While IQAir provides official SDKs, the developer community sometimes contributes additional libraries or wrappers that extend functionality, offer alternative language support, or integrate with specific frameworks. These community-driven projects can vary in maturity, maintenance, and feature completeness compared to official SDKs. Developers often create these to address specific use cases, optimize for certain environments, or provide a more idiomatic interface for a particular language or framework not officially covered.
When considering community libraries, it is advisable to check their GitHub repositories or respective package manager pages for:
- Last update date: To ensure the library is actively maintained and compatible with the latest API versions.
- Issue tracker: To gauge community support and identify known bugs or limitations.
- Documentation: To understand how to use the library effectively and its specific features.
- License: To ensure compatibility with your project's licensing requirements.
For example, developers might find community contributions for integrating IQAir data into specific data visualization tools, IoT platforms, or mobile application frameworks (e.g., React Native, Flutter) that are not directly addressed by the official SDKs. While IQAir's own documentation primarily points to its official SDKs, exploring platforms like GitHub or language-specific package registries (e.g., npm, PyPI) can reveal community efforts. It's important to note that community libraries are not officially supported by IQAir, and their use is at the developer's discretion, requiring independent verification of their reliability and security practices, as outlined in general software development guidelines from sources like Mozilla's developer documentation on SDKs.