Skip to main content

Python client for the AirQo site-location API

Project description

airqolocate

airqolocate creates recommended AirQo sensor locations for a named place. It resolves the OpenStreetMap administrative boundary with OSMnx and submits the resulting polygon to the AirQo Spatial site_location API.

Requirements

  • Python 3.9 or newer
  • An AirQo API token

Installation

Install with place-name lookup support:

pip install "airqolocate[geocoding]"

From this repository:

cd packages/airqo-site-location
python -m pip install -e ".[geocoding]"

Authentication

Pass a token directly or set AIRQO_PLATFORM_TOKEN or AIRQO_API_TOKEN.

$env:AIRQO_API_TOKEN = "your-airqo-api-token"

Quick start

from airqolocate import locate_sites

result = locate_sites(
    "Kampala, Uganda",
    num_sensors=5,
    min_distance_km=2.5,
)

print(result["site_location"])

The library resolves Kampala, Uganda into an OpenStreetMap polygon before calling:

POST https://platform.airqo.net/api/v2/spatial/site_location?token=...

Required locations

must_have_locations is optional. Use it when specific coordinates must be included in the result.

result = locate_sites(
    "Nairobi, Kenya",
    num_sensors=5,
    min_distance_km=2.5,
    must_have_locations=[
        [-1.2790166, 36.816709],
    ],
)

Required locations use [latitude, longitude] order. num_sensors is the total number of returned locations, including required locations.

Client usage

from airqolocate import LocateClient

client = LocateClient(
    token="your-airqo-api-token",
    timeout=60,
)

result = client.locate(
    polygon="Kampala, Uganda",
    num_sensors=5,
    min_distance_km=2.5,
)

Explicit polygon coordinates

Applications that already have a boundary can provide it directly. Polygon positions use GeoJSON [longitude, latitude] order.

polygon = {
    "coordinates": [
        [
            [32.575107, 0.305577],
            [32.607894, 0.312787],
            [32.580342, 0.291845],
            [32.575107, 0.305577],
        ]
    ]
}

result = locate_sites(polygon, num_sensors=3)

Additional API options

Additional supported API fields can be passed through options:

result = client.locate(
    polygon="Kampala, Uganda",
    num_sensors=5,
    options={
        "include_source_metadata": True,
        "include_satellite": False,
        "water_buffer_m": 100,
        "require_water_data": True,
    },
)

Validation and errors

The library validates sensor counts, minimum distance, coordinates, and required-location counts before making the API request. Explicit polygon rings are closed automatically.

Place lookup and request validation errors raise ValueError. Missing OSMnx support raises ImportError. HTTP, network, timeout, invalid JSON, and malformed response errors raise LocateClientError.

from airqolocate import LocateClientError, locate_sites

try:
    result = locate_sites("Kampala, Uganda", num_sensors=5)
except LocateClientError as error:
    print(error.status_code)
    print(error.payload)

Development

cd packages/airqo-site-location
python -m unittest discover -s tests -v
python -m build
python -m twine check dist/*

License

MIT

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

airqolocate-0.1.0.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

airqolocate-0.1.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file airqolocate-0.1.0.tar.gz.

File metadata

  • Download URL: airqolocate-0.1.0.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for airqolocate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e556d642118ea2b57fe7d63f56622ef7b0e3b5f6aa219cde05405dce68db41f5
MD5 8021239e5ca6229cb2c3b1c7640b1a26
BLAKE2b-256 3e33452e9ef0c43c7d65fd8e484c0692714affeaae40d089935a4bdaff5875fa

See more details on using hashes here.

File details

Details for the file airqolocate-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: airqolocate-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.11

File hashes

Hashes for airqolocate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4dd1c11435cab85458f0219e7f3ade51b2b9977e99c0b4bc27d7a0a30e83778d
MD5 71315f4534e1f4f5001d36b30667abea
BLAKE2b-256 4d0cd705737ee70ceca97cd583f2f96883c4cedf8815ed4d73d9677a9078ef4e

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