From 5d075c575266ac19f70a98ed3d303a33d19b7b55 Mon Sep 17 00:00:00 2001 From: Andrew Smith Date: Wed, 26 Mar 2025 18:09:19 +0000 Subject: [PATCH] chore(docs): update example in readme --- README.md | 41 +++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index b4f8501..78922fe 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ This client enables you to use the following Supabase Realtime's features: ## Installing the Package ```bash -pip3 install realtime==2.0.0 +pip3 install realtime ``` ## Creating a Channel @@ -42,23 +42,28 @@ pip3 install realtime==2.0.0 ```python import asyncio from typing import Optional -from realtime.client import RealtimeClient -from realtime.channel import RealtimeSubscribeStates - -client = RealtimeClient(REALTIME_URL, API_KEY) -channel = client.channel('test-channel') - -def _on_subscribe(status: RealtimeSubscribeStates, err: Optional[Exception]): - if status == RealtimeSubscribeStates.SUBSCRIBED: - print('Connected!') - elif status == RealtimeSubscribeStates.CHANNEL_ERROR: - print(f'There was an error subscribing to channel: {err.message}') - elif status == RealtimeSubscribeStates.TIMED_OUT: - print('Realtime server did not respond in time.') - elif status == RealtimeSubscribeStates.CLOSED: - print('Realtime channel was unexpectedly closed.') - -await channel.subscribe(_on_subscribe) + +from realtime import AsyncRealtimeClient, RealtimeSubscribeStates + + +async def main(): + REALTIME_URL = "ws://localhost:4000/websocket" + API_KEY = "1234567890" + + socket = AsyncRealtimeClient(REALTIME_URL, API_KEY) + channel = socket.channel("test-channel") + + def _on_subscribe(status: RealtimeSubscribeStates, err: Optional[Exception]): + if status == RealtimeSubscribeStates.SUBSCRIBED: + print("Connected!") + elif status == RealtimeSubscribeStates.CHANNEL_ERROR: + print(f"There was an error subscribing to channel: {err.args}") + elif status == RealtimeSubscribeStates.TIMED_OUT: + print("Realtime server did not respond in time.") + elif status == RealtimeSubscribeStates.CLOSED: + print("Realtime channel was unexpectedly closed.") + + await channel.subscribe(_on_subscribe) ``` ### Notes: