Skip to content

Client

openaq.client

OpenAQ API client.

Parameters:

NameTypeDescriptionDefault
api_keystr | NoneAPI key for authentication.None
headersMapping[str, str]Additional headers sent with every request.{}
auto_waitboolAutomatically wait when rate limited.True
base_urlstrBase URL for the API endpoint.DEFAULT_BASE_URL
rate_limit_overrideint | NoneInitial rate limit capacity in requests per minute. Corrected automatically from server response headers after the first request.None
_transportTransport | NoneTransport instance for HTTP requests. Internal use only.None

Attributes:

NameTypeDescription
countriesCountriesInterface for the countries resource.
instrumentsInstrumentsInterface for the instruments resource.
licensesLicensesInterface for the licenses resource.
locationsLocationsInterface for the locations resource.
manufacturersManufacturersInterface for the manufacturers resource.
measurementsMeasurementsInterface for the measurements resource.
ownersOwnersInterface for the owners resource.
providersProvidersInterface for the providers resource.
parametersParametersInterface for the parameters resource.
sensorsSensorsInterface for the sensors resource.

Raises:

TypeDescription
ApiKeyMissingErrorMissing API key credentials.
BadRequestErrorHTTP 400 client request error.
NotAuthorizedErrorHTTP 401 client not authorized.
ForbiddenErrorHTTP 403 request forbidden.
NotFoundErrorHTTP 404 resource not found.
TimeoutErrorHTTP 408 request timed out.
ValidationErrorHTTP 422 invalid request parameters.
RateLimitErrorRate limit exceeded and auto_wait is False.
HTTPRateLimitErrorHTTP 429 rate limit exceeded.
ServerErrorHTTP 500 internal server error.
BadGatewayErrorHTTP 502 invalid response from upstream server.
ServiceUnavailableErrorHTTP 503 server not ready to handle the request.
GatewayTimeoutErrorHTTP 504 gateway timeout.
class OpenAQ:
def __init__(
self,
api_key: str | None = None,
headers: Mapping[str, str] | None = None,
auto_wait: bool = True,
base_url: str = DEFAULT_BASE_URL,
_transport: Transport | None = None,
rate_limit_override: int | None = None,
) -> None: ...
@property
def api_key(self) -> str | None: ...
@property
def transport(self) -> Transport: ...
@property
def headers(self) -> Headers: ...
@property
def base_url(self) -> str: ...
def close(self) -> None: ...
def __enter__(self) -> OpenAQ: ...
def __exit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> None: ...

Returns: str | None

The API key used to authenticate requests.

@property
def api_key(self) -> str | None:
return self._api_key

Returns: Transport

The transport instance used to send HTTP requests.

@property
def transport(self) -> Transport:
return self._transport

Returns: Headers

The default headers sent with every request.

@property
def headers(self) -> Headers:
return self._headers

Returns: str

The base URL for the API.

@property
def base_url(self) -> str:
return self._base_url

Closes the transport and releases all pooled connections.

def close(self) -> None:
self._transport.close()