Overview
This is the best page to start from if you want a full Python example quickly.
Setup
1. Create PulseGrid client
2. Test auth
3. Create client token
4. Connect to channel
5. Send websocket message
6. Publish HTTP message
7. Check presence
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="python_tester_1",
identifier_label="Python Tester",
allowed_channels=["demo-channel"],
)
channel = pulsegrid.channel("demo-channel")
print(channel.presence())
print(channel.online_count())
connection = channel.connect(
client_token=token,
on_open=lambda: print("Connected"),
on_message=lambda payload: print(payload),
)
connection.send("Hello from Python websocket")
connection.request_presence_snapshot()
channel.publish(
"Hello from Python server publish",
identifier_id="python_server",
identifier_label="Python Server",
)
Notes
This is the best page to start from if you want a full working example quickly.