Python SDK — air-sdk¶
A small server-side helper for Python 3.10+: it verifies an AIR webhook's signature and parses the body into a typed envelope. It uses only the standard library.
- Repo: https://github.com/Glowar-Ltd/air-sdk-py (private)
- Version: 0.1.0
- Runnable example:
examples/fastapi_app.pyin that repo.
What it is, and what it is not
- Webhook verification only. There is no client for the partner API and no chat client. For those, use the JavaScript SDK, or call the partner API directly.
- Not published. Its README says
pip install air-sdk, but nothing has been published to PyPI. Install it from the private repository. - Its event list is out of date. It knows
overseer.alertand two reserved kinds that AIR never sends to partners (conversation.opened,conversation.ended). Every other event arrives as an unknown event, with the signature verified as usual.
Install¶
From the repository, with access to it:
pip install "git+https://github.com/Glowar-Ltd/air-sdk-py.git"
Verifying a webhook¶
from air_sdk import handle_webhook
result = handle_webhook(
raw_body=raw, # the raw request body, before any JSON parsing
signing_secret=signing_secret,
signature_header=request.headers.get("x-air-signature", ""),
)
if not result.ok:
return Response(result.reason, status_code=result.status)
event = result.envelope # typed envelope: event.event + event.data
It checks one secret at a time. While AIR is
rotating your signing secret, try
each secret in the door's signing_secrets list in turn and accept the
request if any of them verifies.
If you would rather not depend on the package at all, the check is a few lines of standard library — see verifying the signature.
Related¶
- Webhooks — the events AIR actually delivers.
- JavaScript SDK — the full SDK.