Skip to main content

Listen to changes on your supabase postgres database.

Project description

supabase-realtime-client

Python Client Library to interface with the Phoenix Realtime Server This is a fork of the supabase community realtime client library. I am maintaining this fork, to use it under the hood in another project.

Quick Start

import asyncio
from realtime import Socket

def callback1(payload):
    print("Callback 1: ", payload)

def callback2(payload):
    print("Callback 2: ", payload)

async def main() -> None:
    URL = "ws://localhost:4000/socket/websocket"
    s = Socket(URL)
    await s.connect()

    # join channels
    channel_1 = s.set_channel("realtime:public:todos")
    await channel_1.join()
    channel_2 = s.set_channel("realtime:public:users")
    await channel_2.join()

    # register callbacks
    channel_1.on("UPDATE", callback1)
    channel_2.on("*", callback2)

    s.listen()  # infinite loop

Sample usage with Supabase

Here's how you could connect to your realtime endpoint using Supabase endpoint. Please replace SUPABASE_ID and API_KEY with your own SUPABASE_ID and API_KEY. The variables shown below are fake and they will not work if you try to run the snippet.

import asyncio
from realtime import Socket

SUPABASE_ID = "dlzlllxhaakqdmaapvji"
API_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJyb2xlIjoiYW5vbiIsImlhdCI6MT"


def callback1(payload):
    print("Callback 1: ", payload)

async def main() -> None:
    URL = f"wss://{SUPABASE_ID}.supabase.co/realtime/v1/websocket?apikey={API_KEY}&vsn=1.0.0"
    s = Socket(URL)
    await s.connect()

    channel_1 = s.set_channel("realtime:*")
    await channel_1.join()
    channel_1.on("UPDATE", callback1)

    s.listen()

Then, go to the Supabase interface and toggle a row in a table. You should see a corresponding payload show up in your console/terminal.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

supabase-realtime-0.0.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

supabase_realtime-0.0.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file supabase-realtime-0.0.1.tar.gz.

File metadata

  • Download URL: supabase-realtime-0.0.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.9.6 Windows/10

File hashes

Hashes for supabase-realtime-0.0.1.tar.gz
Algorithm Hash digest
SHA256 f6c7e5011bc1828e3b3a1c6d9ef6e6be83cc53a7ff096349260d3a452bab8351
MD5 efd0e179f1f70b8a0d73eb9b12b5038b
BLAKE2b-256 6347b2ef931706e0cfc60274550d12c114d1955cd441044479fd04e382d75eb0

See more details on using hashes here.

File details

Details for the file supabase_realtime-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for supabase_realtime-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d1e12cf5ee155e47996e0c2e199ef751246939b7654a67b1054a597018908cab
MD5 48945dc96ca0237ebd2a1e0dae01c885
BLAKE2b-256 4bd79ebf4b3aa0c19fa6f92a3889ce4419bb387637f06035510cb70017d04ba0

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page