Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/anand2312/supabase-realtime-client
Listen to your supabase database events.
https://github.com/anand2312/supabase-realtime-client
python realtime supabase websockets
Last synced: about 1 month ago
JSON representation
Listen to your supabase database events.
- Host: GitHub
- URL: https://github.com/anand2312/supabase-realtime-client
- Owner: anand2312
- License: mit
- Created: 2021-10-28T13:59:52.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-29T05:25:28.000Z (about 3 years ago)
- Last Synced: 2024-09-06T03:54:55.556Z (2 months ago)
- Topics: python, realtime, supabase, websockets
- Language: Python
- Homepage: https://anand2312.github.io/supabase-realtime-client
- Size: 526 KB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# supabase-realtime-client
Python Client Library to interface with the Phoenix Realtime Server
This is a fork of the [supabase community realtime client library](https://github.com/supabase-community/realtime-py).
I am maintaining this fork, to use it under the hood in another project.## Quick Start
```python
import asyncio
from realtime import Socketdef 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.
```python
import asyncio
from realtime import SocketSUPABASE_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.