Working with the client
Create an instance of the client
OpenAQ Python provides a synchronous client via the OpenAQ
class and an asynchronous client via the AsyncOpenAQ
class, for working with async
/await
within event loops. This guide will show the options on how to create an instance of the client class.
openaq
uses httpx under-the-hood to make http calls to the OpenAQ API. The OpenAQ client follows the same pattern as httpx for opening and closing connections. Once the client is instantiated an httpx.Client
(or httpx.AsyncClient
) is opened and must be explicitly closed after use. This allows for more efficient usage of network resources by maintaining an open connection.
Alternatively we can use a context manager to handle closing the connection for us: