@@ -34,31 +34,36 @@ This client enables you to use the following Supabase Realtime's features:
34
34
## Installing the Package
35
35
36
36
``` bash
37
- pip3 install realtime==2.0.0
37
+ pip3 install realtime
38
38
```
39
39
40
40
## Creating a Channel
41
41
42
42
``` python
43
43
import asyncio
44
44
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)
62
67
```
63
68
64
69
### Notes:
0 commit comments