Python realtime messages

I'm struggling to setup a realtime connection in python. Could someone point me in the right direction? This is my code so far

from realtime.connection import Socket
from supabase.client import Client, ClientOptions, SupabaseRealtimeClient


class SupabaseClient(Client):
    def __init__(
        self, db_id: str, api_key: str, options: ClientOptions = ClientOptions()
    ):
        super().__init__(f"https://{db_id}.supabase.co", api_key, options)

        # Assign supabase id
        self.supabase_id = db_id

        # Create realtime client
        socket = Socket(
            url=f"wss://{db_id}.supabase.co/realtime/v1/websocket?apikey={api_key}&vsn=1.0.0",
            auto_reconnect=True,
        )
        socket.connect()
        self.realtime = SupabaseRealtimeClient(
            socket=socket, schema="public", table_name="*"
        )
        self.realtime.subscribe(self.test_cb)

    def test_cb(self, payload):
        print(payload)


if __name__ == "__main__":
    db = SupabaseClient(db_id="id", api_key="key")
Was this page helpful?