Overview
PulseGrid in Python is designed for backend and trusted service usage.
Recommended Python flow:
1. Create a PulseGrid client
2. Test authentication
3. Create a client token
4. Connect to a channel
5. Send websocket messages
6. Publish server-side events when needed
Setup
1. Install the pulsegrid package from PyPI.
2. Store your base URL, public key, secret key, and project ID in environment variables.
3. Initialize the client with create_pulsegrid(...).
4. Use token helpers and channel helpers for realtime work.
Code example
from pulsegrid import create_pulsegrid
pulsegrid = create_pulsegrid(
base_url="https://www.altrancconnect.com",
public_key="pk_your_public_key",
secret_key="sk_your_secret_key",
project_id="your_project_uuid",
)
token = pulsegrid.tokens.create(
identifier_id="user_123",
identifier_label="Kwandile",
allowed_channels=["demo-channel"],
expires_in=3600,
)
connection = pulsegrid.channel("demo-channel").connect(
client_token=token,
on_open=lambda: print("Connected"),
on_message=lambda payload: print(payload),
)
connection.send("Hello from PulseGrid Python")
Notes
Keep the secret key on the backend only.