Docs

Python: Realtime

Publish to channels, replay missed messages, see presence and channels, open WebSockets with tickets and manage end-to-end encryption keys with the Python SDK.

Updated Nov 12, 2026

supabase-py's channel API: ch = sovaria.channel("room-1"), then ch.on_broadcast("cursor", cb), ch.on_presence_sync(cb), ch.on_postgres_changes("INSERT", cb, table="messages") and await ch.subscribe(); await ch.send_broadcast(event, payload), await ch.track(state), ch.presence_state(), await sovaria.remove_channel(ch). Presence entries carry the user_id the server stamped; table changes carry no row (re-read). Needs the realtime extra.

await sovaria.stream_publish("room:42", {"text": "Hello!"})
missed = await sovaria.stream_replay("room:42", after=last_seen, limit=100)

#Methods

sovaria.channel

A realtime channel, supabase-py style: on_broadcast / on_presence_sync / on_postgres_changes, then await subscribe(); send_broadcast, track, presence_state(), await unsubscribe().

sovaria.channel(name: str, params: dict[str, Any] | None = None) -> Any

Parameters

namestrrequired
paramsdict[str, Any] | Noneoptionaldefault None

Returns

Any

sovaria.e2ee_bootstrap_key

Create (or fetch) the active e2ee channel key.

await sovaria.e2ee_bootstrap_key(
    channel: str,
    *, ttl_seconds: int = 86400,
    force_new: bool = False,
) -> dict[str, Any]

Parameters

channelstrrequired
ttl_secondsintoptionaldefault 86400
force_newbooloptionaldefault False

Returns

dict[str, Any]

{
  "channel": "room-42",
  "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
  "key_id": "k_9f3a2c71",
  "key_b64": null,
  "wrapped_key_b64": "Qm9v…",
  "wrapping_alg": "RSA-OAEP-SHA256",
  "status": "active",
  "created_at_ms": 1792262400000,
  "expires_at_ms": 1792348800000
}

sovaria.e2ee_get_active_key

Get the active e2ee key for a channel, wrapped for client_public_key. Pass an RSA-OAEP (SHA-256) public key as PEM or base64 SPKI; the response's wrapped_key_b64 decrypts with the matching private key.

await sovaria.e2ee_get_active_key(
    channel: str,
    client_public_key: str | None = None,
) -> dict[str, Any]

Parameters

channelstrrequired
client_public_keystr | Noneoptionaldefault None

Returns

dict[str, Any]

{
  "channel": "room-42",
  "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
  "key_id": "k_9f3a2c71",
  "key_b64": null,
  "wrapped_key_b64": "Qm9v…",
  "wrapping_alg": "RSA-OAEP-SHA256",
  "status": "active",
  "created_at_ms": 1792262400000,
  "expires_at_ms": 1792348800000
}

sovaria.e2ee_get_key

Get key material by channel/key_id, wrapped for client_public_key.

await sovaria.e2ee_get_key(
    channel: str,
    key_id: str,
    client_public_key: str | None = None,
) -> dict[str, Any]

Parameters

channelstrrequired
key_idstrrequired
client_public_keystr | Noneoptionaldefault None

Returns

dict[str, Any]

{
  "channel": "room-42",
  "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
  "key_id": "k_9f3a2c71",
  "key_b64": null,
  "wrapped_key_b64": "Qm9v…",
  "wrapping_alg": "RSA-OAEP-SHA256",
  "status": "active",
  "created_at_ms": 1792262400000,
  "expires_at_ms": 1792348800000
}

sovaria.e2ee_list_keys

List key metadata for a channel.

await sovaria.e2ee_list_keys(channel: str) -> dict[str, Any]

Parameters

channelstrrequired

Returns

dict[str, Any]

{
  "channel": "room-42",
  "keys": [
    {
      "channel": "room-42",
      "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
      "key_id": "k_1c7e0b44",
      "status": "active",
      "created_at_ms": 1792265000000,
      "expires_at_ms": 1792351400000,
      "revoked_at_ms": null,
      "revocation_reason": null
    },
    {
      "channel": "room-42",
      "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
      "key_id": "k_9f3a2c71",
      "status": "rotated",
      "created_at_ms": 1792262400000,
      "expires_at_ms": 1792348800000,
      "revoked_at_ms": null,
      "revocation_reason": null
    }
  ]
}

sovaria.e2ee_revoke_key

Revoke an active or historical channel key.

await sovaria.e2ee_revoke_key(
    channel: str,
    *, key_id: str | None = None,
    reason: str | None = None,
) -> dict[str, Any]

Parameters

channelstrrequired
key_idstr | Noneoptionaldefault None
reasonstr | Noneoptionaldefault None

Returns

dict[str, Any]

{
  "channel": "room-42",
  "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
  "key_id": "k_9f3a2c71",
  "status": "revoked",
  "created_at_ms": 1792262400000,
  "expires_at_ms": 1792348800000,
  "revoked_at_ms": 1792266000000,
  "revocation_reason": "device lost"
}

sovaria.e2ee_rotate_key

Rotate e2ee key material for a channel.

await sovaria.e2ee_rotate_key(
    channel: str,
    *, ttl_seconds: int = 86400,
) -> dict[str, Any]

Parameters

channelstrrequired
ttl_secondsintoptionaldefault 86400

Returns

dict[str, Any]

{
  "channel": "room-42",
  "tenant_scope": "b2f4a1c8…:f0c3e9a2…",
  "key_id": "k_1c7e0b44",
  "key_b64": "q1Z8…",
  "wrapped_key_b64": null,
  "wrapping_alg": null,
  "status": "active",
  "created_at_ms": 1792262400000,
  "expires_at_ms": 1792348800000
}

sovaria.get_channels

The channels made with :meth:channel that are still open.

sovaria.get_channels() -> list[Any]

Returns

list[Any]

sovaria.issue_realtime_ws_ticket

Issue a short-lived ticket for opening a realtime WebSocket on one channel.

await sovaria.issue_realtime_ws_ticket(channel: str) -> str

Parameters

channelstrrequired

Returns

str

sovaria.realtime_ws_url

Build the gateway websocket URL for a channel with scope query.

sovaria.realtime_ws_url(
    channel: str,
    *, ticket: str | None = None,
) -> str

Parameters

channelstrrequired
ticketstr | Noneoptionaldefault None

Returns

str

sovaria.realtime_ws_url_with_ticket

Issue a ticket and build the gateway websocket URL for a channel.

await sovaria.realtime_ws_url_with_ticket(channel: str) -> str

Parameters

channelstrrequired

Returns

str

sovaria.remove_all_channels

Remove all channels.

await sovaria.remove_all_channels() -> None

Returns

None

sovaria.remove_channel

Unsubscribe a channel and forget it.

await sovaria.remove_channel(channel: Any) -> None

Parameters

channelAnyrequired

Returns

None

sovaria.stream_channels

List active realtime channels.

await sovaria.stream_channels() -> dict[str, Any]

Returns

dict[str, Any]

{
  "channels": [
    {
      "channel": "room-42",
      "scoped_channel": "b2f4a1c8…:room-42:…",
      "subscribers": 2,
      "event_count": 1834
    }
  ],
  "total": 1
}

sovaria.stream_presence

Fetch presence for a realtime channel.

await sovaria.stream_presence(channel: str) -> dict[str, Any]

Parameters

channelstrrequired

Returns

dict[str, Any]

{
  "channel": "doc-1234",
  "online_clients": [
    "c_7f2a91",
    "c_03bd4e"
  ],
  "count": 2
}

sovaria.stream_publish

Publish a realtime event through the realtime REST API.

await sovaria.stream_publish(
    channel: str,
    payload: dict[str, Any],
    *, clock: dict[str, int] | None = None,
    clock_delta: dict[str, int] | None = None,
) -> dict[str, Any]

Parameters

channelstrrequired
payloaddict[str, Any]required
clockdict[str, int] | Noneoptionaldefault None
clock_deltadict[str, int] | Noneoptionaldefault None

Returns

dict[str, Any]

{
  "channel": "room-42",
  "clock": {
    "pulse-1": 1834
  },
  "clock_delta": {
    "pulse-1": 1
  },
  "stream_seq": 1834,
  "published": true
}

sovaria.stream_replay

Replay events for a realtime channel.

await sovaria.stream_replay(
    channel: str,
    *, after: int = 0,
    limit: int = 200,
) -> dict[str, Any]

Parameters

channelstrrequired
afterintoptionaldefault 0
limitintoptionaldefault 200

Returns

dict[str, Any]

{
  "channel": "room-42",
  "events": [
    {
      "channel": "room-42",
      "scoped_channel": "b2f4a1c8…:room-42:…",
      "payload": {
        "text": "Are you there?",
        "from": "grace"
      },
      "clock": {
        "pulse-1": 1833
      },
      "clock_delta": {
        "pulse-1": 1
      },
      "stream_seq": 1833
    },
    {
      "channel": "room-42",
      "scoped_channel": "b2f4a1c8…:room-42:…",
      "payload": {
        "text": "Hello!",
        "from": "ada"
      },
      "clock": {
        "pulse-1": 1834
      },
      "clock_delta": {
        "pulse-1": 1
      },
      "stream_seq": 1834
    }
  ],
  "count": 2
}

sovaria.stream_subscribe

Subscribe a client ID to a realtime channel.

await sovaria.stream_subscribe(
    channel: str,
    client_id: str,
) -> dict[str, Any]

Parameters

channelstrrequired
client_idstrrequired

Returns

dict[str, Any]

{
  "channel": "orders",
  "subscribed": true
}

sovaria.stream_unsubscribe

Unsubscribe a client ID from a realtime channel.

await sovaria.stream_unsubscribe(
    channel: str,
    client_id: str,
) -> dict[str, Any]

Parameters

channelstrrequired
client_idstrrequired

Returns

dict[str, Any]

{
  "status": "ok"
}

#Ergonomic client

Dot-access channels that mirror the Dart and TypeScript clients: realtime = RealtimeClient(sovaria), then one handle per channel with channel = realtime.channel("room:42"). Publishing and presence go over HTTP; listen() opens a WebSocket with a one-time ticket and reconnects, and needs the realtime extra (pip install 'sovaria-sdk[realtime]'). RealtimeClient also exposes flat realtime.publish(channel, payload) / presence(channel).

`RealtimeClient`

realtime.channel

Return a :class:ChannelRef handle for the named channel.

realtime.channel(name: str) -> ChannelRef

Parameters

namestrrequired

Returns

ChannelRef

realtime.channels

List active realtime channels.

await realtime.channels() -> dict[str, Any]

Returns

dict[str, Any]

`ChannelRef`

channel.write

Send payload on this channel's open socket (from :meth:listen_frames); False when none is open.

await channel.write(payload: dict[str, Any]) -> bool

Presence must go this way: the server keeps a connection's presence only from a track sent on its socket.

Parameters

payloaddict[str, Any]required

Returns

bool

channel.publish

Publish an event to everyone on the channel (over HTTP, no socket needed).

await channel.publish(payload: dict[str, Any]) -> dict[str, Any]

Parameters

payloaddict[str, Any]required

Returns

dict[str, Any]

channel.presence

Who is on the channel right now.

await channel.presence() -> dict[str, Any]

Returns

dict[str, Any]

channel.subscribe

Register a client id as present on the channel.

await channel.subscribe(client_id: str) -> dict[str, Any]

Parameters

client_idstrrequired

Returns

dict[str, Any]

channel.unsubscribe

Remove a client id from the channel.

await channel.unsubscribe(client_id: str) -> dict[str, Any]

Parameters

client_idstrrequired

Returns

dict[str, Any]

channel.replay

Replay recent events on the channel (missed-message catch-up).

await channel.replay(
    *, after: int = 0,
    limit: int = 200,
) -> dict[str, Any]

Parameters

afterintoptionaldefault 0
limitintoptionaldefault 200

Returns

dict[str, Any]

channel.ticket

Issue a one-time ticket for opening the channel's WebSocket.

await channel.ticket() -> str

Returns

str

channel.ws_url

Issue a ticket and build the gateway WebSocket URL for the channel.

await channel.ws_url() -> str

Returns

str

channel.listen

Yield message payloads as they arrive (see :meth:listen_frames, which also gives each whole frame).

channel.listen(
    *, max_backoff: float = 15.0,
    catch_up: bool = True,
    on_gap: Callable[[dict[str, Any]], None] | None = None,
) -> AsyncIterator[dict[str, Any]]

Parameters

max_backofffloatoptionaldefault 15.0
catch_upbooloptionaldefault True
on_gapCallable[[dict[str, Any]], None] | Noneoptionaldefault None

Returns

AsyncIterator[dict[str, Any]]

channel.listen_frames

Yield message payloads as they arrive, reconnecting with backoff.

channel.listen_frames(
    *, max_backoff: float = 15.0,
    catch_up: bool = True,
    on_gap: Callable[[dict[str, Any]], None] | None = None,
    on_open: Callable[[], None] | None = None,
) -> AsyncIterator[tuple[dict[str, Any], dict[str, Any]]]

Breaking out of the async for closes the socket. Stops if the caller is signed out or not allowed on the channel: a refusal at connect or later (close code 4401, 4403, 4408 or 4429) raises RealtimeClosedError with the server's reason. Requires the websockets extra.

After a reconnect (catch_up, on by default) the messages published while the socket was down are fetched from the channel's replay history and yielded first — in order, once each — then live ones. on_gap({"from_seq", "to_seq", "reason"}) is called when messages can't be recovered (older than the retained history, or the history couldn't be read): reload your state from the source of truth then.

Parameters

max_backofffloatoptionaldefault 15.0
catch_upbooloptionaldefault True
on_gapCallable[[dict[str, Any]], None] | Noneoptionaldefault None
on_openCallable[[], None] | Noneoptionaldefault None

Returns

AsyncIterator[tuple[dict[str, Any], dict[str, Any]]]

`RealtimeChannel`

room.on_broadcast

On broadcast.

room.on_broadcast(
    event: str,
    callback: Callable[[dict[str, Any]], Any],
) -> RealtimeChannel

Parameters

eventstrrequired
callbackCallable[[dict[str, Any]], Any]required

Returns

RealtimeChannel

room.on_presence_sync

On presence sync.

room.on_presence_sync(callback: Callable[[], Any]) -> RealtimeChannel

Parameters

callbackCallable[[], Any]required

Returns

RealtimeChannel

room.on_presence_join

On presence join.

room.on_presence_join(
    callback: Callable[[str, list[dict[str, Any]], list[dict[str, Any]]], Any],
) -> RealtimeChannel

Parameters

callbackCallable[[str, list[dict[str, Any]], list[dict[str, Any]]], Any]required

Returns

RealtimeChannel

room.on_presence_leave

On presence leave.

room.on_presence_leave(
    callback: Callable[[str, list[dict[str, Any]], list[dict[str, Any]]], Any],
) -> RealtimeChannel

Parameters

callbackCallable[[str, list[dict[str, Any]], list[dict[str, Any]]], Any]required

Returns

RealtimeChannel

room.on_postgres_changes

On postgres changes.

room.on_postgres_changes(
    event: str,
    callback: Callable[[dict[str, Any]], Any],
    *, table: str,
    schema: str = 'public',
    filter: str | None = None,
) -> RealtimeChannel

Parameters

eventstrrequired
callbackCallable[[dict[str, Any]], Any]required
tablestrrequired
schemastroptionaldefault 'public'
filterstr | Noneoptionaldefault None

Returns

RealtimeChannel

room.subscribe

Start listening.

await room.subscribe(
    callback: Callable[[str, Exception | None], Any] | None = None,
) -> RealtimeChannel

callback("SUBSCRIBED", None) once the channel's socket is open.

Parameters

callbackCallable[[str, Exception | None], Any] | Noneoptionaldefault None

Returns

RealtimeChannel

room.send_broadcast

Send broadcast.

await room.send_broadcast(
    event: str,
    payload: Mapping[str, Any],
) -> None

Parameters

eventstrrequired
payloadMapping[str, Any]required

Returns

None

room.track

Track.

await room.track(state: Mapping[str, Any]) -> None

Parameters

stateMapping[str, Any]required

Returns

None

room.untrack

Untrack.

await room.untrack() -> None

Returns

None

room.presence_state

Presence state.

room.presence_state() -> dict[str, list[dict[str, Any]]]

Returns

dict[str, list[dict[str, Any]]]

room.unsubscribe

Unsubscribe.

await room.unsubscribe() -> None

Returns

None