SDKs overview

The PM2.5 Open Data Portal offers direct access to its data via a RESTful API. While the portal does not provide first-party, officially supported SDKs, its simple API structure allows developers to integrate directly using standard HTTP request libraries available in most programming languages. This approach, common for many public data APIs, prioritizes broad accessibility over language-specific wrappers. Instead, the community has developed several libraries to simplify interaction with the portal's data, particularly for analysis and visualization tasks in popular environments like Python and R.

Integrating with a REST API directly typically involves making HTTP GET requests to specific endpoints and parsing the JSON responses. For example, a developer might use Python's requests library or JavaScript's fetch API to retrieve data. Community-developed libraries often abstract these HTTP calls, providing higher-level functions to fetch data, handle pagination, and structure the output into language-specific data types, such as pandas DataFrames in Python or data.tables in R, which are well-suited for data analysis. The MDN Web Docs on HTTP status codes provide a comprehensive reference for understanding API responses.

Official SDKs by language

As of 2026-05-29, the PM2.5 Open Data Portal does not offer any officially maintained Software Development Kits (SDKs). The primary method for programmatic interaction is through its REST API. This means developers directly interact with the API endpoints by constructing HTTP requests and parsing the JSON responses.

Language Package Name Install Command (Example) Maturity
None N/A N/A N/A

For most integrations, a generic HTTP client library available in your chosen programming language will suffice. These libraries handle the low-level details of making web requests, allowing developers to focus on data retrieval and processing. For instance, in Python, the requests library is a popular choice for making HTTP calls, while in JavaScript, the built-in fetch API is commonly used. The official IETF RFC 7230 defines the Hypertext Transfer Protocol (HTTP/1.1) message syntax and routing, providing the foundational principles for these interactions.

Installation

Since there are no official SDKs, installation typically involves setting up a basic HTTP client library in your preferred programming language. The following sections provide examples for common languages, demonstrating how to prepare your development environment to interact with the PM2.5 Open Data Portal API.

Python

For Python, the requests library is widely used for making HTTP requests. It is not part of the standard library and needs to be installed via pip:

pip install requests

After installation, you can import it into your Python script:

import requests

R

In R, the httr package provides a comprehensive set of tools for working with HTTP. It can be installed from CRAN:

install.packages("httr")

Then, load the package in your R session:

library(httr)

JavaScript (Node.js/Browser)

JavaScript environments (both Node.js and browsers) often use the built-in fetch API. For Node.js environments where fetch might not be natively available in older versions, or for more advanced features, the node-fetch library can be used, or a library like axios:

# For Node.js if fetch is not native or preferring axios
npm install axios

In a browser, fetch is globally available. In Node.js with axios, you would import it:

// Browser (fetch is globally available)
// Node.js with axios
const axios = require('axios');

Quickstart example

This section provides a quickstart example demonstrating how to retrieve real-time PM2.5 data from the PM2.5 Open Data Portal API using Python, R, and JavaScript, leveraging common HTTP client libraries. The example fetches data for a specific area (e.g., Taipei).

Python Quickstart

This Python example uses the requests library to make a GET request to the API and then prints the JSON response. This provides a direct method for accessing the air quality data.

import requests
import json

# API endpoint for PM2.5 data (example for a specific location/area)
# Refer to the PM2.5 Open Data Portal's API documentation for specific endpoints:
# https://pm25.lass-net.org/en/info/#api
api_url = "https://pm25.lass-net.org/monitor/" # This is a general endpoint

try:
    response = requests.get(api_url)
    response.raise_for_status()  # Raise an exception for HTTP errors (4xx or 5xx)
    data = response.json()
    
    print("Successfully fetched data:")
    # Print first few entries or summary to avoid overwhelming output
    if data and "feeds" in data and len(data["feeds"]) > 0:
        print(f"Number of feeds received: {len(data['feeds'])}")
        print("First feed entry:")
        print(json.dumps(data["feeds"][0], indent=2))
    else:
        print("No data feeds found or unexpected response structure.")

except requests.exceptions.HTTPError as http_err:
    print(f"HTTP error occurred: {http_err}")
except requests.exceptions.ConnectionError as conn_err:
    print(f"Connection error occurred: {conn_err}")
except requests.exceptions.Timeout as timeout_err:
    print(f"Timeout error occurred: {timeout_err}")
except requests.exceptions.RequestException as req_err:
    print(f"An unexpected error occurred: {req_err}")
except json.JSONDecodeError:
    print("Failed to decode JSON from response.")
    print(f"Response content: {response.text[:500]}...")

R Quickstart

This R example uses the httr package to fetch data and then the jsonlite package to parse the JSON response. This is typical for data analysis workflows in R.

library(httr)
library(jsonlite)

# API endpoint for PM2.5 data
api_url <- "https://pm25.lass-net.org/monitor/"

response <- GET(api_url)

# Check for successful response
if (http_status(response)$category == "Success") {
  content <- content(response, "text", encoding = "UTF-8")
  data <- fromJSON(content)
  
  cat("Successfully fetched data:\n")
  # Print first few entries or summary
  if ("feeds" %in% names(data) && length(data$feeds) > 0) {
    cat(paste0("Number of feeds received: ", length(data$feeds), "\n"))
    cat("First feed entry:\n")
    print(head(data$feeds, 1))
  } else {
    cat("No data feeds found or unexpected response structure.\n")
  }
} else {
  cat(paste0("Error fetching data: ", http_status(response)$reason, "\n"))
  cat(content(response, "text"))
}

JavaScript Quickstart (Browser/Node.js with Fetch)

This JavaScript example uses the fetch API to retrieve data asynchronously. This approach is standard for web applications and modern Node.js environments.

// API endpoint for PM2.5 data
const apiUrl = "https://pm25.lass-net.org/monitor/";

async function getPm25Data() {
  try {
    const response = await fetch(apiUrl);
    
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    
    const data = await response.json();
    
    console.log("Successfully fetched data:");
    if (data && data.feeds && data.feeds.length > 0) {
        console.log(`Number of feeds received: ${data.feeds.length}`);
        console.log("First feed entry:");
        console.log(JSON.stringify(data.feeds[0], null, 2));
    } else {
        console.log("No data feeds found or unexpected response structure.");
    }

  } catch (error) {
    console.error("Error fetching PM2.5 data:", error);
  }
}

getPm25Data();

Community libraries

The PM2.5 Open Data Portal's open API has led to the development of several community-contributed libraries. These libraries often encapsulate the HTTP request logic and provide convenience functions for parsing and working with the data in specific programming environments. While not officially supported, they can significantly reduce development time.

Python

  • pm25-api-python (example of potential library name): While no single widely adopted official Python SDK exists, community scripts and utility functions are often shared on platforms like GitHub or PyPI. These typically involve wrappers around the requests library to fetch specific datasets (e.g., historical data for a sensor) and convert them into pandas DataFrames for easy analysis. Developers often create their own small utilities to handle specific data transformation needs.

R

  • r-pm25-lass (example of potential library name): Similar to Python, R users frequently develop helper functions or packages for environmental data analysis. These might leverage httr for requests and jsonlite for parsing, then integrate with data manipulation packages like dplyr or data.table. These community efforts are often found in academic or open-source projects focused on environmental monitoring.

JavaScript / TypeScript

  • pm25-data-fetcher (example of potential library name): For web-based or Node.js applications, community libraries might abstract the fetch API calls, provide TypeScript definitions for the API response structure, and offer methods to filter or aggregate data. These are useful for building dashboards or integrating air quality data into larger applications.

When considering a community library, it is advisable to check its maintenance status, documentation, and the activity of its maintainers to ensure it remains compatible with potential API changes and is suitable for production use. The Google Open Source Project Criteria offers useful guidelines for evaluating the quality and sustainability of open-source projects.