Server SDK

Realtime WebSocket Events for Python — Django, Flask & FastAPI

Trigger real-time WebSocket events from Django, Flask, and FastAPI. Zero-dependency server SDK using only the Python standard library — no WebSocket server to run or manage.

Server $ pip install apinator-server
Client $ npm install @apinator/client

Sending real-time WebSocket notifications from a Python backend doesn't require running a separate WebSocket server or process. Apinator's Python server SDK lets you publish events from Django views, Flask routes, or FastAPI endpoints with a single API call. The persistent WebSocket connections live on Apinator's infrastructure — your Python application just triggers events when something happens.

Quick Start

How to add realtime WebSocket events to Django, Flask, or FastAPI

Add realtime features to your Python app in a few steps.

01

Install the server SDK

Add the Python server SDK. Zero dependencies — uses only the standard library.

pip install apinator-server
02

Initialize the client

Create an Apinator client with your app credentials. Works with any Python framework.

from apinator import Apinator client = Apinator( app_id="your-app-id", key="your-key", secret="your-secret", cluster="us" )
03

Trigger WebSocket events from your views

Publish real-time WebSocket events from any Python backend — Django views, Flask routes, FastAPI endpoints, or Celery tasks.

client.trigger( "new-order", json.dumps({"total": "$49.99"}), channel="private-orders" )
04

Authenticate private channels

Add an endpoint that authenticates channel subscriptions for your frontend clients.

auth = client.authenticate_channel( socket_id, channel_name ) # Returns {"auth": "key:signature"}

Why Python

Built for Python developers

Zero Dependencies

Uses only Python stdlib — hashlib, hmac, urllib, json. No requests, no httpx, no bloat.

Works Everywhere

Django, Flask, FastAPI, Tornado, or plain scripts. Any Python 3.10+ environment.

Py

Type Hints

Full type annotations throughout. Works with mypy and Pyright for static type checking.

Webhook Verification

Verify incoming webhook signatures with a single method call. Replay attack protection included.

How to add WebSocket notifications to a Python backend

Python web frameworks like Django, Flask, and FastAPI are built around the request/response cycle — they don't maintain persistent connections out of the box. Adding WebSocket support traditionally required integrating additional libraries (Django Channels, python-socketio, websockets) and running separate worker processes alongside your existing web server, each with their own configuration and operational overhead.

Apinator takes a different approach. Your Python backend doesn't manage any WebSocket connections. Instead, you make a simple HTTPS API call using Apinator's SDK to publish an event — from a Django view, a Celery task, a FastAPI background task, or any other Python code. Apinator's servers maintain the persistent WebSocket connections to your browser clients and deliver the event in real-time, typically in under 100ms.

The Python SDK has zero dependencies. It uses only Python's standard library — hmac, hashlib, urllib.request — to sign requests and publish events. This means no additions to requirements.txt, no dependency conflicts, and no compatibility issues across Python 3.10+ environments regardless of the framework.

Full Example

Full Example: Realtime WebSocket Dashboard with Django

Complete WebSocket example: Django views for channel authentication and event publishing, plus a JavaScript frontend that receives real-time updates.

views.py
import json from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from django.views.decorators.http import require_POST from apinator import Apinator from django.conf import settings client = Apinator( app_id=settings.REALTIME_APP_ID, key=settings.REALTIME_KEY, secret=settings.REALTIME_SECRET, cluster=settings.REALTIME_CLUSTER, ) @csrf_exempt @require_POST def realtime_auth(request): body = json.loads(request.body) auth = client.authenticate_channel( body["socket_id"], body["channel_name"] ) return JsonResponse(auth) @require_POST def send_update(request): data = json.loads(request.body) client.trigger( "dashboard-update", json.dumps(data), channel="private-dashboard" ) return JsonResponse({"ok": True})

Start building realtime Python apps

Completely free. No credit card. No catch.