Skip to main content
Documentation Note: This quickstart demonstrates the intended usage patterns for AQI prediction. For actual implementation and availability, please refer to the GitHub repository.

Get Started in 3 Steps

This guide demonstrates the typical workflow for installing and using an AQI prediction system.
1

Install AQI Predictor

Install the Python package using pip:
pip install aqi-predictor
AQI Predictor requires Python 3.8 or higher. Check your Python version with python --version
2

Get Your API Key

Sign up for a free account and obtain your API key. Contact your administrator or visit the project repository to get access credentials.Once you have your API key:
Keep your API key secure! Never commit it to version control or share it publicly.
Store your API key as an environment variable:
export AQI_API_KEY="your_api_key_here"
Or create a .env file:
.env
AQI_API_KEY=your_api_key_here
3

Make Your First Prediction

Create a Python script and make your first AQI prediction:
predict.py
from aqi_predictor import AQIClient
import os

# Initialize the client
client = AQIClient(api_key=os.getenv("AQI_API_KEY"))

# Prepare environmental data
environmental_data = {
    "temperature": 25.5,      # Temperature in Celsius
    "humidity": 65,           # Relative humidity (%)
    "pressure": 1013.25,      # Atmospheric pressure (hPa)
    "wind_speed": 3.2,        # Wind speed (m/s)
    "pm25": 12.3,            # PM2.5 concentration (μg/m³)
    "pm10": 22.1,            # PM10 concentration (μg/m³)
    "no2": 15.2,             # NO2 concentration (ppb)
    "o3": 35.6,              # O3 concentration (ppb)
    "location": {
        "lat": 37.7749,      # San Francisco coordinates
        "lon": -122.4194
    }
}

# Get prediction
prediction = client.predict(environmental_data)

# Display results
print(f"Predicted AQI: {prediction.aqi}")
print(f"Category: {prediction.category}")
print(f"Confidence: {prediction.confidence:.2%}")
print(f"Health Recommendation: {prediction.health_message}")
Run your script:
python predict.py
Predicted AQI: 42
Category: Good
Confidence: 94.23%
Health Recommendation: Air quality is satisfactory, and air pollution poses little or no risk.

Understanding the Response

The prediction response includes several fields:
aqi
integer
The predicted Air Quality Index value (0-500)
category
string
The AQI category: Good, Moderate, Unhealthy for Sensitive Groups, Unhealthy, Very Unhealthy, or Hazardous
confidence
float
Model confidence score (0-1) indicating prediction reliability
health_message
string
Human-readable health recommendation based on the predicted AQI
timestamp
string
ISO 8601 timestamp of when the prediction was made
components
object
Breakdown of individual pollutant contributions to the AQI

Try Different Scenarios

Experiment with different environmental conditions to see how they affect AQI predictions:
# Simulate high pollution conditions
high_pollution = {
    "temperature": 32.0,
    "humidity": 45,
    "wind_speed": 1.2,  # Low wind speed
    "pm25": 85.4,        # High PM2.5
    "pm10": 120.3,       # High PM10
    "no2": 62.1,
    "location": {"lat": 34.0522, "lon": -118.2437}
}

result = client.predict(high_pollution)
# Expected: AQI ~150-180 (Unhealthy)

Batch Predictions

Need to process multiple locations or time periods? Use batch predictions:
from aqi_predictor import AQIClient

client = AQIClient(api_key=os.getenv("AQI_API_KEY"))

# Multiple predictions in one request
locations = [
    {"temperature": 25.5, "humidity": 65, "pm25": 12.3, "location": {"lat": 37.7749, "lon": -122.4194}},
    {"temperature": 28.1, "humidity": 58, "pm25": 18.7, "location": {"lat": 34.0522, "lon": -118.2437}},
    {"temperature": 22.3, "humidity": 72, "pm25": 9.1, "location": {"lat": 40.7128, "lon": -74.0060}},
]

predictions = client.batch_predict(locations)

for i, pred in enumerate(predictions):
    print(f"Location {i+1}: AQI {pred.aqi} - {pred.category}")

Using the REST API

Prefer to use the REST API directly? Here’s how:
curl -X POST https://api.aqipredictor.com/v1/predict \
  -H "X-API-Key: your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "temperature": 25.5,
    "humidity": 65,
    "pm25": 12.3,
    "pm10": 22.1,
    "no2": 15.2,
    "location": {"lat": 37.7749, "lon": -122.4194}
  }'

Next Steps

Now that you’ve made your first prediction, explore more advanced features:

Installation Guide

Learn about advanced installation options and dependencies

Core Concepts

Understand how AQI prediction works under the hood

Training Models

Train custom models on your regional data

API Reference

Explore the complete API documentation
Pro tip: Start with pre-trained models for quick results, then train custom models on your regional data for improved accuracy.

Build docs developers (and LLMs) love