Skip to content

Locations

The Locations resource provides air monitoring stations data from the OpenAQ database. You can use it to get details about stations: where they are located, what instruments they use, what pollutants they measure, and who owns or manages them. The resource has methods to query single stations, search many stations, and access live sensor data. This resource helps you work with station information and current conditions.

The Locations resource provides the following methods:

  • get() - For accessing a single location by location ID.
  • list() - For accessing multiple locations.
  • latest() - For accessing the latest measurements for all sensors for a given location ID.
  • sensors() - For accessing a list of available sensors at the location for a given location ID.

The get() method accepts one single locations_id as an argument and returns details about that location in a LocationsResponse object.

get(
locations_id: int
) -> LocationsResponse
argumentdescriptioninput requirements
locations_idint OpenAQ’s unique ID for a locationRequired
from openaq import OpenAQ
# Retrieve the location with ID 4845127
with OpenAQ(api_key="replace-me-with-a-valid-key") as client:
client.locations.get(4845127)

The list() method takes optional arguments and returns locations on the OpenAQ platform that meet all the conditions specified in a LocationsResponse object. If no argument is included, the method returns all locations using the default arguments.

list(
page: int = 1,
limit: int = 100,
radius: int | None = None,
coordinates: tuple[float, float] | None = None,
bbox: tuple[float, float, float, float] | None = None,
providers_id: int | list[int] | None = None,
countries_id: int | list[int] | None = None,
parameters_id: int | list[int] | None = None,
licenses_id: int | list[int] | None = None,
instruments_id: int | list[int] | None = None,
manufacturers_id: int | list[int] | None = None,
owners_id: int | list[int] | None = None,
iso: str | None = None,
monitor: bool | None = None,
mobile: bool | None = None,
order_by: str | None = None,
sort_order: str | None = None
) -> LocationsResponse
argumentdescriptioninput requirements
pageint The page number to retrieve, defaults to 1Must be greater than zero
limitint The number of results returned per page, defaults to 100Must be between 1 and 1,000
radiusint | None How far (in meters) to search for locations around the coordinate pairMust be between 1 and 25,000. Must be accompanied by coordinates argument. Cannot be used at the same time as bbox
coordinatestuple[float, float] | None The geographic position of a point from which to search for locationsMust be in WGS84 (EPSG:4326) in (latitude, longitude) or (Y, X) format and accompanied by radius. Cannot be used at the same time as bbox
bboxtuple[float, float, float, float] | None The rectangular area within which locations are searched for and returnedMust be in WGS84 (EPSG:4326) and (minX, minY, maxX, maxY) format with maximum 4 decimals precision. Cannot be used at the same time as coordinates or radius
providers_idint | list[int] | None Filter by the ID of the data providerMust be OpenAQ unique ID for the provider that facilitates data sharing
countries_idint | list[int] | None Filter by the country or territory where the location operatesMust be OpenAQ unique ID for the country or territory. Cannot be used at the same time as iso
parameters_idint | list[int] | None Filter by a pollutant or meteorological parameterMust be OpenAQ unique ID for the pollutant or meteorological parameter
licenses_idint | list[int] | None Filter by the license that governs the usage and sharing of data at the locationMust be OpenAQ unique ID for the license
instruments_idint | list[int] | None Filter by the instrument or equipment that gathers data at the locationMust be OpenAQ unique ID for the instrument
manufacturers_idint | list[int] | None Filter by the company or organization that produces the air quality monitoring instruments at the locationMust be OpenAQ unique ID for the manufacturer
owners_idint | list[int] | None Filter by the owner that owns and reports the data at the locationMust be OpenAQ unique ID for the owner
isostr | None The ISO 3166-1 alpha-2 code for the country or territory where the location operatesMust be a valid ISO 3166-1 alpha-2 code representation of the country. Cannot be used at the same time as countries_id
monitorbool | None Filter for reference-grade monitors (True) or air sensor (False) locations
mobilebool | None Filter for mobile (True) or stationary (False) locations
order_bystr | None The location field by which to sort results, defaults to id. Currently only id is supported
sort_orderstr | None The sort direction for the order_by field, defaults to descMust be one of: asc, desc, ASC, DESC
from openaq import OpenAQ
# List all locations in Morocco where there is a PM2.5 reading
with OpenAQ(api_key="your-api-key") as client:
client.locations.list(countries_id=27,
parameters_id=2)

The latest() method takes one single locations_id as an argument and returns the last measurement readings of all sensors at that location in a LatestResponse object.

.latest(
locations_id: int
) -> LatestResponse
argumentdescriptioninput requirements
locations_idint OpenAQ’s unique ID for each locationRequired
from openaq import OpenAQ
# Retrieve the latest measurement readings at the location with ID 4845127
with OpenAQ(api_key="your-api-key") as client:
client.locations.latest(4845127)

The sensors() method accepts one single locations_id as an argument and returns all sensors at that location in a SensorsResponse object.

.sensors(
locations_id: int
) -> SensorsResponse
argumentdescriptioninput requirements
locations_idint OpenAQ’s unique ID for a locationRequired
from openaq import OpenAQ
# Retrieve all sensors at location with ID 4845127
with OpenAQ(api_key="your-api-key") as client:
client.locations.sensors(4845127)

The Location, Latest, and Sensor objects in the results of their respective response contain attributes that have all data about them. The hierarchy below presents the depth of the attributes and their datatypes.

results[]
├── id: int
├── name: str
├── locality: str | None
├── timezone: str
├── country:
│ ├── id: int
│ ├── code: str
│ └── name: str
├── owner:
│ ├── id: int
│ └── name: str
├── provider:
│ ├── id: int
│ └── name: str
├── is_mobile: bool
├── is_monitor: bool
├── instruments: []
│ ├── id: int
│ └── name: str
├── sensors: []
│ ├── id: int
│ ├── name: str
│ └── parameter:
│ ├── id: int
│ ├── name: str
│ ├── units: str
│ └── display_name: str | None
├── coordinates
│ ├── latitude: float
│ └── longitude: float
├── bounds: tuple[float, float, float, float]
├── distance: float | None
├── datetime_first
│ ├── utc: str
│ └── local: str
└── datetime_last
├── utc: str
└── local: str
results[]
├── datetime:
│ ├── utc: str
│ └── local: str
├── value: float
├── coordinates:
│ ├── latitude: float
│ └── longitude: float
├── sensors_id: int
└── locations_id: int
results[]
├── id: int
├── name: str
├── parameter
│ ├── id: int
│ ├── name: str
│ ├── units: str
│ └── displayName: str
├── datetime_first
│ ├── utc: str
│ └── local: str
├── datetime_last
│ ├── utc: str
│ └── local: str
├── coverage
│ ├── expectedCount: int
│ ├── expectedInterval: str
│ ├── observedCount: int
│ ├── observedInterval: str
│ ├── percentComplete: float
│ ├── percentCoverage: float
│ ├── datetimeFrom
│ │ ├── utc: str
│ │ └── local: str
│ └── datetimeTo
│ ├── utc: str
│ └── local: str
├── latest
│ ├── datetime
│ │ ├── utc: str
│ │ └── local: str
│ ├── value: float
│ └── coordinates
│ ├── latitude: float
│ └── longitude: float
└── summary
├── min: float
├── q02: float | None
├── q25: float | None
├── median: float | None
├── q75: float | None
├── q98: float | None
├── max: float
├── avg: float
└── sd: float