Skip to content

Concepts

Live queries

A live query subscribes to a table and receives a notification whenever a matching record is created, updated, or deleted. Notifications arrive on the WebSocket transport out of band, and the SDK queues them as they come in.

MethodDescription
client.live_query()Starts a live query on a table
client.kill()Stops a running live query
Note

Live queries run over a stateful WebSocket session. WebSocket support is rolling out. On the HTTP transport, the engine reports live_queries=False and the SDK raises an UnsupportedFeatureError.

Starts a live query on a table and returns the query id as a string. Notifications arrive out of band and are queued by the transport; pull them out with poll_notifications().

Method Syntax
client.live_query(table, session)
ArgumentDescription
tableThe table to subscribe to.
sessionAn optional session id.
var query_id = client.live_query("person")

To get the full RpcResponse instead of just the query id, use live_raw(table, session).

The transport queues notifications as they arrive. Pull them out with poll_notifications(), which drains every queued notification across all live queries.

var notifications = client.poll_notifications()
for ref in notifications:
    print(ref[].query_id, ref[].action)

Each entry is a LiveNotificationRaw carrying the query id, the action, and the raw record bytes.

Stops a running live query, using the query id returned by live_query().

Method Syntax
client.kill(query_id, session)
ArgumentDescription
query_idThe id of the live query to stop.
sessionAn optional session id.
var query_id = client.live_query("person")
# ... later ...
client.kill(query_id)

Was this page helpful?

Last updated