Skip to content

Logging

The OpenAQ client uses the Python standard libary logging module. No extra dependencies are needed, you control verbosity through Python’s built-in logging configuration.

The simplest way to see all debug output is to enable logging at the DEBUG level before creating the client:

import logging
import openaq
logging.basicConfig(level=logging.DEBUG)
with openaq.OpenAQ(api_key="replace-me-with-a-valid-key") as client:
results = client.locations.list()

This prints all log messages from the openaq logger and every other library in your process, to stderr.

To see only OpenAQ-specific messages without noise from other libraries, configure the openaq logger directly:

import logging
import openaq
logger = logging.getLogger("openaq")
logger.setLevel(logging.DEBUG)
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter("%(asctime)s [%(levelname)s] %(name)s: %(message)s"))
logger.addHandler(handler)
with openaq.OpenAQ(api_key="replace-me-with-a-valid-key") as client:
results = client.locations.list()

LevelWhat you’ll see
DEBUGFull request/response details, rate limit state changes
INFORate limit waits (when auto_wait=True sleeps before retrying)
WARNINGUnexpected but recoverable conditions
ERRORMissing API key, rate limit exceeded (when auto_wait=False)