This library also provides a client for accessing the Airthings web API. The code in wave_reader/web
is mostly generated by openapi-python-client
using the
official OpenAPI schema published by Airthings.
As with any versioned schema, breaking changes are possible by upstream developments. If you notice anything that isn't working correctly, please open a bug ticket.
Check out the official specification to see what functionality is available.
First, create a client:
from wave_reader.web import client
handler = client.OAuth2ClientHandler(client_id, client_secret, redirect_uri)
handler.new_authorization_url()
handler.new_access_token()
client = handler.new_client()
Now call your endpoint and use the models:
from wave_reader.web.models.get_device_detailed_response import GetDeviceDetailedResponse
from wave_reader.web.api.devices import device_info
from wave_reader.web.types import Response
response: Response[GetDeviceDetailedResponse] = device_info.sync_detailed(1234567890, client=client)
Or do the same thing with an async version:
from wave_reader.web.models.get_device_detailed_response import GetDeviceDetailedResponse
from wave_reader.web.api.devices import device_info
from wave_reader.web.types import Response
response: Response[GetDeviceDetailedResponse] = await device_info.asyncio_detailed(1234567890, client=client)
All path/query params, and bodies become method arguments. In the example above, the serial number is required.
See examples
for a concrete code sample.
-
Every path/method combo becomes a Python module with four functions:
sync
: Blocking request that returns parsed data (if successful) orNone
sync_detailed
: Blocking request that always returns aRequest
, optionally withparsed
set if the request was successful.asyncio
: Likesync
but the async instead of blockingasyncio_detailed
: Likesync_detailed
by async instead of blocking
-
All path/query params, and bodies become method arguments.
-
If your endpoint had any tags on it, the first tag will be used as a module name for the function (my_tag above)
-
Any endpoint which did not have a tag will be in
wave_reader.web.api.default
The code in api
and models
is auto-generated and won't be covered in testing. Bugs that may occur in the future
will likely result from upstream API schema changes and that is out of our control.