For AI agents: the documentation index is at llms.txt. Guide pages have a markdown version at the same path with .md appended, before any query string or fragment.
on_presence_sync(), on_presence_join(), or on_presence_leave()). If you add presence callbacks to an already joined channel, the channel will automatically resubscribe with presence enabled.REPLICA IDENTITY to FULL (e.g., ALTER TABLE your_table REPLICA IDENTITY FULL;).channel = supabase.channel("room1")
def on_subscribe(status, err):
if status == RealtimeSubscribeStates.SUBSCRIBED:
asyncio.create_task(channel.send_broadcast(
"cursor-pos",
{"x": random.random(), "y": random.random()}
))
def handle_broadcast(payload):
print("Cursor position received!", payload)
await channel.on_broadcast(event="cursor-pos", callback=handle_broadcast).subscribe(on_subscribe)
channel = supabase.channel("room1")
def on_subscribe(status, err):
if status == RealtimeSubscribeStates.SUBSCRIBED:
asyncio.create_task(channel.track({"online_at": datetime.datetime.now().isoformat()}))
def handle_presence_sync():
print("Synced presence state: ", channel.presence.state)
await channel.on_presence_sync(callback=handle_presence_sync).subscribe(on_subscribe)
channel = supabase.channel("room1")
def handle_presence_join(key, current_presence, new_presence):
print("Newly joined presences: ", new_presence)
def on_subscribe(status, err):
if status == RealtimeSubscribeStates.SUBSCRIBED:
asyncio.create_task(channel.track({"online_at": datetime.datetime.now().isoformat()}))
await channel.on_presence_join(callback=handle_presence_join).subscribe(on_subscribe)
channel = supabase.channel("room1")
def handle_presence_leave(key, current_presence, left_presence):
print("Newly left presences: ", left_presence)
def on_subscribe(status, err):
if status == RealtimeSubscribeStates.SUBSCRIBED:
asyncio.create_task(channel.track({"online_at": datetime.datetime.now().isoformat()}))
asyncio.create_task(channel.untrack())
await channel.on_presence_leave(callback=handle_presence_leave).subscribe(on_subscribe)
response = (
await supabase.channel("room1")
.on_postgres_changes("*", schema="*", callback=handle_record_updated)
.subscribe()
)
response = (
await supabase.channel("room1")
.on_postgres_changes("*", schema="public", table="countries", callback=handle_record_updated)
.subscribe()
)
response = (
await supabase.channel("room1")
.on_postgres_changes("INSERT", schema="public", table="countries", callback=handle_record_inserted)
.subscribe()
)
response = (
await supabase.channel("room1")
.on_postgres_changes("UPDATE", schema="public", table="countries", callback=handle_record_updated)
.subscribe()
)
response = (
await supabase.channel("room1")
.on_postgres_changes("DELETE", schema="public", table="countries", callback=handle_record_deleted)
.subscribe()
)
response = (
await supabase.channel("room1")
.on_postgres_changes("INSERT", schema="public", table="countries", callback=handle_record_inserted)
.on_postgres_changes("DELETE", schema="public", table="countries", callback=handle_record_deleted)
.subscribe()
)
response = (
await supabase.channel("room1")
.on_postgres_changes("UPDATE", schema="public", table="countries", filter="id=eq.200", callback=handle_record_updated)
.subscribe()
)
def handle_record_updated(payload):
print("Updated country:", payload)
response = (
await supabase.channel("room1")
.on_postgres_changes(
"UPDATE",
schema="public",
table="countries",
select=["id", "name"],
callback=handle_record_updated,
)
.subscribe()
)