Skip to main content

Python SDK for the AQI.in Air Quality API

Project description

py-aqi-in-api

Python SDK for the AQI.in Air Quality API.

Fully typed, async, using modern Python (3.11+), dataclasses, and httpx.

Source: This is a Python port of the aqi-in-api TypeScript SDK by @neo773.

Installation

pip install py-aqi-in-api

Requires Python 3.11+.

Usage

import asyncio

from aqi_in_api import AQIClient


async def main() -> None:
    client = AQIClient()

    ip_details = await client.get_ip_details()
    print(f"Location: {ip_details.city}, {ip_details.country}")

    nearest = await client.get_nearest_location(
        lat=ip_details.lat, long=ip_details.lon,
    )
    station = nearest[0]
    print(f"Nearest station: {station.station} ({station.location_slug})")

    location = await client.get_location_by_slug(slug=station.location_slug)
    print(f"Location AQI: {location[0].iaqi}")

    history = await client.get_last_24_hour_history(
        slug=station.location_slug, sensorname="pm25", slug_type="locationId",
    )
    print(f"24h PM2.5 avg: {history.avgValue}")

    await client.close()


asyncio.run(main())

API

create_aqi_client(config?)

Option Type Required Description
token str | None No JWT authentication token (auto-generated if omitted)
base_url str No API base URL (default: https://apiserver.aqi.in)
user_agent str No Custom user agent

Methods

All methods take keyword-only arguments. No *Params objects needed.

Method Keyword Args Returns Description
get_ip_details() IPDetails Get location from your IP address
get_nearest_location(**kwargs) lat, long, type? list[Station] Get nearest monitoring stations by coordinates
get_location_by_slug(**kwargs) slug, type? list[LocationDetails] Get location details by slug
search(**kwargs) search_string SearchResults Search locations by name
get_last_12_hour_history(**kwargs) slug, sensorname, slug_type HistoryData Get 12-hour sensor history
get_last_24_hour_history(**kwargs) slug, sensorname, slug_type HistoryDataWithWHO Get 24-hour history with WHO guidelines
get_last_7_days_history(**kwargs) slug, sensorname, slug_type HistoryDataWithWHO Get 7-day sensor history
get_last_30_days_history(**kwargs) slug, sensorname, slug_type HistoryDataWithWHO Get 30-day sensor history
get_rankings(**kwargs) sensorname, type, limit=10 list[RankingEntry] Get city or country pollution rankings
close() None Close the underlying HTTP client

Types

from aqi_in_api.models import (
    Station, City, State, Country,
    LocationDetails, IPDetails, SearchResults, RankingEntry,
    HistoryData, HistoryDataWithWHO,
    IAQI, Weather, WeatherCondition, WeatherSimple, UVCondition,
    SensorName, SearchType, SlugType, LocationType, RankType,
)

Development

git clone https://github.com/GuyKh/py-aqi-in-api
cd py-aqi-in-api
uv sync --dev
uv run pytest
uv run ruff check .

License

MIT

Disclaimer

This is an unofficial API client and is not affiliated with, endorsed by, or associated with AQI.in or its parent organization. This package is provided for educational and informational purposes under fair use.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aqi_in_api-0.0.2.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aqi_in_api-0.0.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file aqi_in_api-0.0.2.tar.gz.

File metadata

  • Download URL: aqi_in_api-0.0.2.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aqi_in_api-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4810745ae5c8eb64c11db982fa39b7a6f6ac79fc7ddee2bfc841f18610b6e2e8
MD5 81d0a8ede8890937e70ea10775fbfe81
BLAKE2b-256 9ee9c58388737747c997ae26c91610db3e9e8c8ffca3265e21ec15e6b82fd8e0

See more details on using hashes here.

File details

Details for the file aqi_in_api-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: aqi_in_api-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.25 {"installer":{"name":"uv","version":"0.11.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for aqi_in_api-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ab8f45a70a8e34cc1e59101570b5cae45a3fbc5c73f0995eb1852941c8794876
MD5 b387e953c2c6dbaa3c47b8ba17b8af31
BLAKE2b-256 63cb216cd399c9cbcb3b037dde97b3b9e226b5fdaff16715cb01db8e08888ad9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page