Server SDK · Python backends
Python SDK
Python 3.10+. Uses the standard library with no runtime dependencies.
Install from GitHub
The SDK source is public on the main branch. Use the release installation instructions below; source branches can differ from published packages.
pip install "git+https://github.com/pubbio/sdk-python.git@main"
Install into your existing virtual environment. Replace main with a verified commit to pin the dependency.
Publish an event
Set PUBB_APP_ID, PUBB_APP_KEY and PUBB_APP_SECRET in your server environment, then publish after checking the caller's permissions.
import os
from pubb import PubbServer
pubb = PubbServer(os.environ["PUBB_APP_ID"], os.environ["PUBB_APP_KEY"],
os.environ["PUBB_APP_SECRET"])
result = pubb.trigger("notifications", "message.sent", {"message": "Hello from Pubb!"})
print(result.publication_id)
Calls are synchronous and use a configurable timeout. trigger accepts socket_id and idempotency_key keyword arguments. PubbAPIError exposes status and retry_after; PubbProtocolError indicates an invalid response. Network errors propagate from urllib.
HTTP 202 confirms acceptance for processing, not delivery. The response includes publicationId and duplicate. SDKs do not automatically retry publications; reuse an idempotency key when retrying the same event. The API accepts 1–100 channels and up to 10 KiB of UTF-8 JSON data.
Private and presence channels
Return authorize_channel(socket_id, channel) or authorize_presence_channel(socket_id, channel, verified_user_id, user_info) from your authenticated backend route after checking channel permissions.
Your backend receives socket_id and channel_name, checks the authenticated user’s access, and returns auth plus channel_data for presence. Derive the presence user ID from the session and forward the signed channel_data unchanged.
Keep the app secret on your trusted server. Public channels must not carry personal or restricted data. Read the WebSocket Protocol Reference for channel authorization and exact wire messages.
Client events
Applications can opt into scoped WebSocket publishing. The updated JavaScript and Unity clients accept a separate publishing permission; JavaScript and .NET server helpers issue it after your access checks. Other SDK releases can use the documented wire protocol. Read Client events for setup, expiry, revocation and acknowledgement semantics.
Verify your integration
- Subscribe to
notificationsin your app or the dashboard’s Live console. - Publish
message.sentto the same application and channel from your backend. - Check the event payload, connection cleanup and recovery after a disconnect. Test denied access as well as successful private subscriptions.
The repositories include automated tests and examples. Verify end-to-end delivery with your own application before sending production traffic. Refetch durable state after reconnecting; missed events are not replayed.