SDKs overview
AQICN provides an API for accessing air quality index data, which developers can integrate into their applications to display real-time, historical, and forecast information. The platform supports direct HTTP requests to its RESTful API and offers official and community-contributed Software Development Kits (SDKs) and libraries to streamline this integration process. These SDKs abstract away the complexities of making raw HTTP requests, handling API key authentication, and parsing JSON responses, allowing developers to interact with the AQICN API using native language constructs and objects. This approach can accelerate development by providing structured access to data points such as the Air Quality Index (AQI), pollutant concentrations, and station metadata.
The AQICN API is designed to deliver data covering various locations globally, supporting queries by city, geographic coordinates, and station ID. Developers often utilize these SDKs in applications ranging from environmental monitoring dashboards and smart home integrations to academic research projects requiring air quality metrics. The availability of SDKs across multiple programming languages reflects the diverse development environments in which AQICN data is consumed. For comprehensive details on API endpoints and parameters, developers can refer to the AQICN API reference documentation.
Official SDKs by language
AQICN's official support for SDKs primarily focuses on direct API integration via well-documented examples and code snippets rather than fully packaged, versioned SDKs in traditional package managers for every language. The platform emphasizes clear API documentation and examples that illustrate how to construct requests and parse responses in various programming languages, providing a foundation for developers to build their own integrations or utilize community libraries. While explicit SDK packages in repositories like npm or PyPI might be less prevalent directly from AQICN, the detailed code examples serve a similar purpose, guiding developers through the implementation process.
The following table outlines the languages for which AQICN provides official guidance and examples, along with common installation approaches for developing an API client. Developers typically include these libraries as dependencies in their project to manage HTTP requests and JSON data.
| Language | Common HTTP Library / Approach | Typical Installation Command | Maturity |
|---|---|---|---|
| JavaScript (Node.js/Browser) | axios, fetch API |
npm install axios or native fetch |
Stable (via common web standards) |
| Python | requests |
pip install requests |
Stable (via common Python libraries) |
| PHP | GuzzleHttp/guzzle |
composer require guzzlehttp/guzzle |
Stable (via common PHP libraries) |
| Ruby | httparty or native Net::HTTP |
gem install httparty |
Stable (via common Ruby gems) |
| Java | OkHttp, Apache HttpClient |
Add to pom.xml (Maven) or build.gradle (Gradle) |
Stable (via common Java libraries) |
| Go | Native net/http package |
No explicit install; part of standard library | Stable (via standard Go library) |
Installation
Installing the necessary components for interacting with the AQICN API typically involves adding a suitable HTTP client library to your project, as AQICN provides API usage examples rather than dedicated SDKs through package managers. The specific installation method depends on your chosen programming language and build system.
JavaScript / Node.js
For JavaScript environments, the axios library is a common choice for making HTTP requests:
npm install axios
Alternatively, in modern browser and Node.js environments (v18+), the native fetch API can be used without external installation.
Python
The requests library is a popular and robust HTTP client for Python:
pip install requests
PHP
For PHP projects, Guzzle is a widely used HTTP client. It is typically installed via Composer:
composer require guzzlehttp/guzzle
Ruby
In Ruby, the httparty gem simplifies HTTP requests:
gem install httparty
The standard library's Net::HTTP module can also be used without any additional installation.
Java
For Java development, libraries like OkHttp or Apache HttpClient are common. If using Maven, add the dependency to your pom.xml:
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.9.3</version>
</dependency>
For Gradle, add to build.gradle:
implementation 'com.squareup.okhttp3:okhttp:4.9.3'
Go
Go uses its built-in net/http package for HTTP requests, requiring no external installation:
import (
"net/http"
"io/ioutil"
)
Quickstart example
This example demonstrates how to fetch real-time air quality data for a specific city using Python and the requests library. This approach is consistent with the AQICN API documentation, which provides similar examples for other languages.
First, ensure you have an AQICN API token. Replace YOUR_API_TOKEN and CITY_NAME with your actual token and desired city.
import requests
import json
API_TOKEN = "YOUR_API_TOKEN" # Replace with your actual API token
CITY = "london" # Replace with the city you want to query
def get_air_quality(city_name, token):
base_url = "https://api.waqi.info/feed/"
url = f"{base_url}{city_name}/?token={token}"
try:
response = requests.get(url)
response.raise_for_status() # Raise an exception for HTTP errors (4xx or 5xx)
data = response.json()
if data and data['status'] == 'ok':
aqi = data['data']['aqi']
print(f"Current AQI in {city_name.capitalize()}: {aqi}")
# You can access more data points like dominant pollutant, forecast, etc.
# print(json.dumps(data['data'], indent=2))
else:
print(f"Error fetching AQI for {city_name}: {data.get('data', 'Unknown error')}")
except requests.exceptions.RequestException as e:
print(f"Network or API error: {e}")
except json.JSONDecodeError:
print("Error decoding JSON response.")
if __name__ == "__main__":
get_air_quality(CITY, API_TOKEN)
This script initializes the API token and target city, constructs the request URL, and sends a GET request. Upon a successful response, it parses the JSON data to extract and print the current Air Quality Index (AQI).
Community libraries
While AQICN provides robust API documentation and examples, the developer community has created several unofficial libraries and wrappers to further simplify integration in specific programming languages and frameworks. These community efforts often build upon the core principles outlined in the official documentation, adding features such as object-oriented interfaces, error handling enhancements, and framework-specific integrations. Community-developed resources can be found on platforms like GitHub or language-specific package repositories.
Developers are encouraged to review the source code and community support of any third-party library before integrating it into production systems, as their maintenance and stability can vary. Examples of common community-driven approaches include:
- Python Wrappers: Developers often create simple Python classes or functions to encapsulate API calls, manage authentication, and provide cleaner data access. These might focus on specific use cases like fetching data for a list of stations or integrating with data science libraries.
- JavaScript/TypeScript Clients: For web applications, community libraries might offer typed interfaces for the API responses, better integration with React, Vue, or Angular frameworks, or advanced caching mechanisms.
- Mobile Development SDKs: While less common for AQICN specifically, some developers might build minimal native wrappers for Android (Kotlin/Java) or iOS (Swift/Objective-C) to simplify API calls within mobile applications.
Searching platforms like GitHub for AQICN-related repositories can yield various community contributions. When using community libraries, it is important to check the last update date, open issues, and the number of contributors to assess their ongoing support and reliability, as recommended by general software development best practices for software supply chain security.