Python server SDK for Apinator — trigger real-time events, authenticate channels, and verify webhooks.
- Trigger events on public, private, and presence channels
- Channel authentication (HMAC-SHA256)
- Webhook signature verification
- Channel introspection (list channels, get channel info)
- Zero external dependencies — Python 3.10+ stdlib only
- Full type hints throughout
pip install apinator-serverfrom apinator import Apinator
client = Apinator(
app_id="your-app-id",
key="your-app-key",
secret="your-app-secret",
cluster="eu", # or "us"
)
# Trigger an event
client.trigger(
"new-message",
'{"text": "Hello!"}',
channel="chat-room",
)For private and presence channels, your backend must provide an auth endpoint:
from apinator import Apinator
client = Apinator(
app_id="your-app-id",
key="your-app-key",
secret="your-app-secret",
cluster="eu",
)
# In your auth route handler:
socket_id = request.form["socket_id"]
channel_name = request.form["channel_name"]
auth = client.authenticate_channel(socket_id, channel_name)
# Return auth as JSON responseFor presence channels, include channel data:
import json
channel_data = json.dumps({
"user_id": current_user.id,
"user_info": {"name": current_user.name},
})
auth = client.authenticate_channel(socket_id, channel_name, channel_data)from apinator import Apinator
client = Apinator(
app_id="your-app-id",
key="your-app-key",
secret="your-webhook-secret",
cluster="eu",
)
# In your webhook route handler:
headers = dict(request.headers)
body = request.get_data(as_text=True)
if client.verify_webhook(headers, body, max_age=300):
# Webhook is valid — process the payload
payload = json.loads(body)
else:
# Invalid webhook
abort(401)# List all channels
channels = client.get_channels()
# Filter by prefix
presence_channels = client.get_channels(prefix="presence-")
# Get info about a specific channel
info = client.get_channel("presence-chat")See docs/api-reference.md for the full API.
MIT — see LICENSE.