Code Monkey home page Code Monkey logo

supabase-realtime-client's Introduction

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.

supabase-realtime-client's People

Contributors

lionellloh avatar anand2312 avatar j0 avatar prettyirrelevant avatar bitnom avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.