Skip to content

Commit 126309c

Browse files
authored
chore(docs): update example in readme (#294)
1 parent 99f0150 commit 126309c

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

README.md

+23-18
Original file line numberDiff line numberDiff line change
@@ -34,31 +34,36 @@ This client enables you to use the following Supabase Realtime's features:
3434
## Installing the Package
3535

3636
```bash
37-
pip3 install realtime==2.0.0
37+
pip3 install realtime
3838
```
3939

4040
## Creating a Channel
4141

4242
```python
4343
import asyncio
4444
from typing import Optional
45-
from realtime.client import RealtimeClient
46-
from realtime.channel import RealtimeSubscribeStates
47-
48-
client = RealtimeClient(REALTIME_URL, API_KEY)
49-
channel = client.channel('test-channel')
50-
51-
def _on_subscribe(status: RealtimeSubscribeStates, err: Optional[Exception]):
52-
if status == RealtimeSubscribeStates.SUBSCRIBED:
53-
print('Connected!')
54-
elif status == RealtimeSubscribeStates.CHANNEL_ERROR:
55-
print(f'There was an error subscribing to channel: {err.message}')
56-
elif status == RealtimeSubscribeStates.TIMED_OUT:
57-
print('Realtime server did not respond in time.')
58-
elif status == RealtimeSubscribeStates.CLOSED:
59-
print('Realtime channel was unexpectedly closed.')
60-
61-
await channel.subscribe(_on_subscribe)
45+
46+
from realtime import AsyncRealtimeClient, RealtimeSubscribeStates
47+
48+
49+
async def main():
50+
REALTIME_URL = "ws://localhost:4000/websocket"
51+
API_KEY = "1234567890"
52+
53+
socket = AsyncRealtimeClient(REALTIME_URL, API_KEY)
54+
channel = socket.channel("test-channel")
55+
56+
def _on_subscribe(status: RealtimeSubscribeStates, err: Optional[Exception]):
57+
if status == RealtimeSubscribeStates.SUBSCRIBED:
58+
print("Connected!")
59+
elif status == RealtimeSubscribeStates.CHANNEL_ERROR:
60+
print(f"There was an error subscribing to channel: {err.args}")
61+
elif status == RealtimeSubscribeStates.TIMED_OUT:
62+
print("Realtime server did not respond in time.")
63+
elif status == RealtimeSubscribeStates.CLOSED:
64+
print("Realtime channel was unexpectedly closed.")
65+
66+
await channel.subscribe(_on_subscribe)
6267
```
6368

6469
### Notes:

0 commit comments

Comments
 (0)