Skip to content

apinator-io/sdk-python

Repository files navigation

apinator-server

PyPI Version License: MIT CI

Python server SDK for Apinator — trigger real-time events, authenticate channels, and verify webhooks.

Features

  • 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

Installation

pip install apinator-server

Quick Start

from 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",
)

Channel Authentication

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 response

For 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)

Webhook Verification

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)

Channel Introspection

# 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")

API Reference

See docs/api-reference.md for the full API.

Links

License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages