Realtime example

Hi, I am able to get realtime working in the browser with the inspector to confirm that it's setup correctly:

However, when I try it with python or javscript, I can't seem to get it to work. Does anybody have any suggestions?

import os
from supabase import create_async_client, AClient
from dotenv import load_dotenv

class SupabaseClient:
    def __init__(self):
        load_dotenv()
        self.url: str = os.environ.get("SUPABASE_URL")
        self.key: str = os.environ.get("SUPABASE_KEY")
        self.client: AClient = None

    async def login(self):
        self.client = await create_async_client(self.url, self.key)
        await self.client.realtime.connect()


    async def subscribe(self):
        # await self.client.channel('schema-db-changes').on_postgres_changes("*", schema="*", table="*", callback=lambda payload: print(payload)).subscribe()
        await self.client.channel('schema-db-changes').on_postgres_changes(
            "*",
            schema="public",
            callback=lambda payload: print(payload)
        ).subscribe()
        await self.client.channel('schema-db-changes').on_postgres_changes(
            "INSERT",
            schema="public",
            callback=lambda payload: print(payload)
        ).subscribe()

if __name__ == '__main__':
    import asyncio

    async def main():
        client = SupabaseClient()
        await client.login()
        await client.subscribe()
        print("Press Ctrl+C to exit")
        while True:
            await asyncio.sleep(1)

    asyncio.run(main())


import { createClient } from '@supabase/supabase-js'

const supabase = createClient('URL HERE', 'KEY HERE')

const channel = supabase
  .channel('schema-db-changes')
  .on(
    '*',
    {
      event: 'INSERT',
      schema: 'public',
    },
    (payload) => console.log(payload)
  )
  .subscribe()
Screenshot_2025-01-16_at_6.25.39_AM.png
Was this page helpful?