@@ -28,6 +28,13 @@ let client = Client::new(
2828 EncodingKind :: Cbor , // Encoding (Json or Cbor)
2929);
3030```
31+
32+ ``` python Python
33+ from actor_core_client import AsyncClient as ActorClient
34+
35+ # Create a client with the connection address
36+ client = ActorClient(" http://localhost:6420" )
37+ ```
3138</CodeGroup >
3239
3340<Tip >See the setup guide for your platform for details on how to get the connection address.</Tip >
@@ -76,6 +83,17 @@ room.action("sendMessage", vec![json!("Alice"), json!("Hello everyone!")])
7683 . await
7784 . expect (" Failed to send message" );
7885```
86+
87+ ``` python Python
88+ # Connect to a chat room for the "general" channel
89+ room = await client.get(" chatRoom" , tags = [
90+ (" name" , " chat_room" ),
91+ (" channel" , " general" )
92+ ])
93+
94+ # Now you can call methods on the actor
95+ await room.action(" sendMessage" , [" Alice" , " Hello everyone!" ])
96+ ```
7997</CodeGroup >
8098
8199### ` create(opts) ` - Explicitly Create New
@@ -125,6 +143,16 @@ doc.action("initializeDocument", vec![json!("My New Document")])
125143 . await
126144 . expect (" Failed to initialize document" );
127145```
146+
147+ ``` python Python
148+ # Create a new document actor
149+ doc = await client.get(" myDocument" , tags = [
150+ (" name" , " my_document" ),
151+ (" docId" , " 123" )
152+ ])
153+
154+ await doc.action(" initializeDocument" , [" My New Document" ])
155+ ```
128156</CodeGroup >
129157
130158### ` getWithId(id, opts) ` - Connect by ID
@@ -148,7 +176,7 @@ let my_actor_id = "55425f42-82f8-451f-82c1-6227c83c9372";
148176let options = GetWithIdOptions {
149177 params : None ,
150178};
151- let doc = client . get_with_id (" myDocument " , my_actor_id , options )
179+ let doc = client . get_with_id (my_actor_id , options )
152180 . await
153181 . expect (" Failed to connect to document" );
154182
@@ -157,6 +185,14 @@ doc.action("updateContent", vec![json!("Updated content")])
157185 . await
158186 . expect (" Failed to update document" );
159187```
188+
189+ ``` python Python
190+ # Connect to a specific actor by its ID
191+ my_actor_id = " 55425f42-82f8-451f-82c1-6227c83c9372"
192+ doc = await client.get_with_id(my_actor_id)
193+
194+ await doc.action(" updateContent" , [" Updated content" ])
195+ ```
160196</CodeGroup >
161197
162198<Note >
@@ -208,6 +244,22 @@ game_room.action("updateSettings", vec![settings])
208244 . await
209245 . expect (" Failed to update settings" );
210246```
247+
248+ ``` python Python
249+ # Call an action
250+ result = await math_utils.action(" multiplyByTwo" , [5 ])
251+ print (result) # 10
252+
253+ # Call an action with multiple parameters
254+ await chat_room.action(" sendMessage" , [" Alice" , " Hello everyone!" ])
255+
256+ # Call an action with an object parameter
257+ await game_room.action(" updateSettings" , [{
258+ " maxPlayers" : 10 ,
259+ " timeLimit" : 300 ,
260+ " gameMode" : " capture-the-flag"
261+ }])
262+ ```
211263</CodeGroup >
212264
213265<Note >
@@ -256,6 +308,24 @@ game_room.on_event("stateUpdate", move |args| {
256308 game_ui_clone . update (game_state );
257309}). await ;
258310```
311+
312+ ``` python Python
313+ # Listen for new chat messages
314+ def handle_message (message ):
315+ sender = message[" sender" ]
316+ text = message[" text" ]
317+ print (f " { sender} : { text} " )
318+ # Update UI with message data
319+
320+ chat_room.on_event(" newMessage" , handle_message)
321+
322+ # Listen for game state updates
323+ def handle_state_update (game_state ):
324+ # Update UI with new game state
325+ update_game_ui(game_state)
326+
327+ game_room.on_event(" stateUpdate" , handle_state_update)
328+ ```
259329</CodeGroup >
260330
261331### ` once(eventName, callback) ` - One-time Listening
@@ -274,6 +344,15 @@ actor.once("requestApproved", () => {
274344``` rust Rust
275345// `once` is not implemented in Rust
276346```
347+
348+ ``` python Python
349+ # Listen for when a request is approved
350+ def handle_approval ():
351+ show_approval_notification()
352+ unlock_features()
353+
354+ actor.on_event(" requestApproved" , handle_approval)
355+ ```
277356</CodeGroup >
278357
279358## Connection Options
@@ -318,6 +397,18 @@ let chat_room = client.get("chatRoom", options)
318397 . await
319398 . expect (" Failed to connect to chat room" );
320399```
400+
401+ ``` python Python
402+ chat_room = await client.get(
403+ " chatRoom" ,
404+ tags = [(" channel" , " super-secret" )],
405+ params = {
406+ " userId" : " 1234" ,
407+ " authToken" : " eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." ,
408+ " displayName" : " Alice"
409+ }
410+ )
411+ ```
321412</CodeGroup >
322413
323414The actor can access these parameters in the ` onBeforeConnect ` or ` createConnState ` hook:
@@ -391,6 +482,19 @@ let client = Client::new(
391482
392483// Rust does not support accepting multiple transports
393484```
485+
486+ ``` python Python
487+ from actor_core_client import AsyncClient as ActorClient
488+
489+ # Example with all client options
490+ client = ActorClient(
491+ " https://actors.example.com" ,
492+ " websocket" # or "sse"
493+ " cbor" , # or "json"
494+ )
495+
496+ # Python does not support accepting multiple transports
497+ ```
394498</CodeGroup >
395499
396500### ` encoding `
@@ -490,6 +594,11 @@ actor.disconnect().await;
490594// Or explicitly drop it with:
491595drop (client );
492596```
597+
598+ ``` python Python
599+ # Disconnect from the actor
600+ await actor.disconnect()
601+ ```
493602</CodeGroup >
494603
495604## Offline and Auto-Reconnection
0 commit comments