Skip to content

Commit 61c2a21

Browse files
authored
Merge pull request #3148 from ably/AIT-289/python-mutable-messages-docs
[AIT-289] feat: ably-python mutable messages docs
2 parents 4629104 + 64d97aa commit 61c2a21

4 files changed

Lines changed: 167 additions & 9 deletions

File tree

src/data/languages/languageData.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export default {
1313
kotlin: '1.6',
1414
objc: '1.2',
1515
php: '1.1',
16-
python: '2.1',
16+
python: '3.0',
1717
ruby: '1.2',
1818
swift: '1.2',
1919
go: '1.3',
@@ -29,7 +29,7 @@ export default {
2929
kotlin: '1.6',
3030
objc: '1.2',
3131
php: '1.1',
32-
python: '2.1',
32+
python: '3.0',
3333
ruby: '1.2',
3434
swift: '1.2',
3535
go: '1.3',

src/pages/docs/api/realtime-sdk/channels.mdx

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ Failure to retrieve the message history will trigger the `errback` callbacks of
824824

825825
</If>
826826

827-
<If lang="javascript,nodejs,java">
827+
<If lang="javascript,nodejs,java,python">
828828

829829
#### getMessage
830830

@@ -836,6 +836,10 @@ Failure to retrieve the message history will trigger the `errback` callbacks of
836836
`Message getMessage(String serial)`
837837
</If>
838838

839+
<If lang="python">
840+
`Message get_message(serial_or_message)`
841+
</If>
842+
839843
Retrieves the latest version of a specific message by its serial identifier. Requires the **history** [capability](/docs/auth/capabilities).
840844

841845
See [updating and deleting messages: retrieving the latest version](/docs/messages/updates-deletes#get) for more information.
@@ -862,6 +866,18 @@ Returns a promise which, upon success, will be fulfilled with a [`Message`](/doc
862866
Returns a [`Message`](/docs/api/realtime-sdk/messages) object representing the latest version of the message.
863867
</If>
864868

869+
<If lang="python">
870+
| Parameter | Description | Type |
871+
|-----------|-------------|------|
872+
| serial_or_message | Either the serial identifier string of the message to retrieve, or a `Message` object containing a populated `serial` field | `str` or `Message` |
873+
874+
##### Returns
875+
876+
Returns a [`Message`](/docs/api/realtime-sdk/messages) object representing the latest version of the message.
877+
878+
On failure, raises an [`AblyException`](/docs/api/realtime-sdk/types#ably-exception).
879+
</If>
880+
865881
#### updateMessage
866882

867883
<If lang="javascript,nodejs">
@@ -872,6 +888,10 @@ Returns a [`Message`](/docs/api/realtime-sdk/messages) object representing the l
872888
`void updateMessage(Message message, MessageOperation operation, Callback<UpdateDeleteResult> callback)`
873889
</If>
874890

891+
<If lang="python">
892+
`UpdateDeleteResult update_message(message, operation=None, params=dict())`
893+
</If>
894+
875895
Publishes an update to an existing message with shallow mixin semantics. Non-null `name`, `data`, and `extras` fields in the provided message will replace the corresponding fields in the existing message, while null fields will be left unchanged. Requires the **message-update-own** or **message-update-any** [capability](/docs/auth/capabilities).
876896

877897
See [updating and deleting messages: updates](/docs/messages/updates-deletes#update) for more information.
@@ -895,6 +915,14 @@ Returns a promise which, upon success, will be fulfilled with an [`UpdateDeleteR
895915
Invokes the provided `Callback<UpdateDeleteResult>` with an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-result) object containing the new version of the message on success, or with an [`ErrorInfo`](/docs/api/realtime-sdk/types#error-info) object describing the error on failure.
896916
</If>
897917

918+
<If lang="python">
919+
##### Returns
920+
921+
Returns an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-result) object containing the new version of the message.
922+
923+
On failure, raises an [`AblyException`](/docs/api/realtime-sdk/types#ably-exception).
924+
</If>
925+
898926
#### deleteMessage
899927

900928
<If lang="javascript,nodejs">
@@ -905,6 +933,10 @@ Invokes the provided `Callback<UpdateDeleteResult>` with an [`UpdateDeleteResult
905933
`void deleteMessage(Message message, MessageOperation operation, Callback<UpdateDeleteResult> callback)`
906934
</If>
907935

936+
<If lang="python">
937+
`UpdateDeleteResult delete_message(message, operation=None, params=dict())`
938+
</If>
939+
908940
Marks a message as deleted by publishing an update with an action of `MESSAGE_DELETE`. This does not remove the message from the server, and the full message history remains accessible. Uses shallow mixin semantics: non-null `name`, `data`, and `extras` fields in the provided message will replace the corresponding fields in the existing message, while null fields will be left unchanged. Requires the **message-delete-own** or **message-delete-any** [capability](/docs/auth/capabilities).
909941

910942
See [updating and deleting messages: deletes](/docs/messages/updates-deletes#delete) for more information.
@@ -928,6 +960,14 @@ Returns a promise which, upon success, will be fulfilled with an [`UpdateDeleteR
928960
Invokes the provided `Callback<UpdateDeleteResult>` with an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-result) object containing the new version of the message on success, or with an [`ErrorInfo`](/docs/api/realtime-sdk/types#error-info) object describing the error on failure.
929961
</If>
930962

963+
<If lang="python">
964+
##### Returns
965+
966+
Returns an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-result) object containing the new version of the message.
967+
968+
On failure, raises an [`AblyException`](/docs/api/realtime-sdk/types#ably-exception).
969+
</If>
970+
931971
#### appendMessage
932972

933973
<If lang="javascript,nodejs">
@@ -938,6 +978,10 @@ Invokes the provided `Callback<UpdateDeleteResult>` with an [`UpdateDeleteResult
938978
`void appendMessage(Message message, MessageOperation operation, Callback<UpdateDeleteResult> callback)`
939979
</If>
940980

981+
<If lang="python">
982+
`UpdateDeleteResult append_message(message, operation=None, params=dict())`
983+
</If>
984+
941985
Appends data to an existing message. The supplied `data` field is appended to the previous message's data, while all other fields (`name`, `extras`) replace the previous values if provided. Requires the **message-update-own** or **message-update-any** [capability](/docs/auth/capabilities).
942986

943987
See [updating and deleting messages: appends](/docs/messages/updates-deletes#append) for more information.
@@ -961,6 +1005,14 @@ Returns a promise which, upon success, will be fulfilled with an [`UpdateDeleteR
9611005
Invokes the provided `Callback<UpdateDeleteResult>` with an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-result) object containing the new version of the message on success, or with an [`ErrorInfo`](/docs/api/realtime-sdk/types#error-info) object describing the error on failure.
9621006
</If>
9631007

1008+
<If lang="python">
1009+
##### Returns
1010+
1011+
Returns an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-result) object containing the new version of the message.
1012+
1013+
On failure, raises an [`AblyException`](/docs/api/realtime-sdk/types#ably-exception).
1014+
</If>
1015+
9641016
#### getMessageVersions
9651017

9661018
<If lang="javascript,nodejs">
@@ -971,6 +1023,10 @@ Invokes the provided `Callback<UpdateDeleteResult>` with an [`UpdateDeleteResult
9711023
`PaginatedResult<Message> getMessageVersions(String serial, Param[] params)`
9721024
</If>
9731025

1026+
<If lang="python">
1027+
`PaginatedResult get_message_versions(serial_or_message, params = dict())`
1028+
</If>
1029+
9741030
Retrieves all historical versions of a specific message, ordered by version. This includes the original message and all subsequent updates or delete operations. Requires the **history** [capability](/docs/auth/capabilities).
9751031

9761032
See [updating and deleting messages: message versions](/docs/messages/updates-deletes#versions) for more information.
@@ -988,7 +1044,7 @@ See [updating and deleting messages: message versions](/docs/messages/updates-de
9881044
Returns a promise which, upon success, will be fulfilled with a [`PaginatedResult`](#paginated-result) object containing an array of [`Message`](/docs/api/realtime-sdk/messages) objects representing all versions of the message. Upon failure, the promise will be rejected with an [`ErrorInfo`](/docs/api/realtime-sdk/types#error-info) object which explains the error.
9891045
</If>
9901046

991-
<If lang="java">
1047+
<If lang="java,python">
9921048
##### Returns
9931049

9941050
On success, the returned [`PaginatedResult`](#paginated-result) encapsulates an array of [`Message`](#message) objects corresponding to the current page of results. [`PaginatedResult`](#paginated-result) supports pagination using [`next`](#paginated-result) and [`first`](#paginated-result) methods.

src/pages/docs/api/rest-sdk/channels.mdx

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ On failure to retrieve message history, the `error` contains an [`ErrorInfo`](#e
465465

466466
</If>
467467

468-
<If lang="javascript,nodejs">
468+
<If lang="javascript,nodejs,java,python">
469469

470470
#### getMessage <a id="get-message" />
471471

@@ -477,6 +477,10 @@ On failure to retrieve message history, the `error` contains an [`ErrorInfo`](#e
477477
`Message getMessage(String serial)`
478478
</If>
479479

480+
<If lang="python">
481+
`Message get_message(serial_or_message)`
482+
</If>
483+
480484
Retrieves the latest version of a specific message by its serial identifier. Requires the **history** [capability](/docs/auth/capabilities).
481485

482486
See [updating and deleting messages: retrieving the latest version](/docs/messages/updates-deletes#get) for more information.
@@ -503,6 +507,18 @@ Returns a promise which, upon success, will be fulfilled with a [`Message`](/doc
503507
Returns a [`Message`](/docs/api/realtime-sdk/messages) object representing the latest version of the message.
504508
</If>
505509

510+
<If lang="python">
511+
| Parameter | Description | Type |
512+
|-----------|-------------|------|
513+
| serial_or_message | Either the serial identifier string of the message to retrieve, or a `Message` object containing a populated `serial` field | `str` or `Message` |
514+
515+
##### Returns
516+
517+
Returns a [`Message`](/docs/api/realtime-sdk/messages) object representing the latest version of the message.
518+
519+
On failure, raises an [`AblyException`](/docs/api/realtime-sdk/types#ably-exception).
520+
</If>
521+
506522
#### updateMessage <a id="update-message" />
507523

508524
<If lang="javascript,nodejs">
@@ -513,6 +529,10 @@ Returns a [`Message`](/docs/api/realtime-sdk/messages) object representing the l
513529
`UpdateDeleteResult updateMessage(Message message, MessageOperation operation)`
514530
</If>
515531

532+
<If lang="python">
533+
`UpdateDeleteResult update_message(message, operation=None, params=dict())`
534+
</If>
535+
516536
Publishes an update to an existing message with shallow mixin semantics. Non-null `name`, `data`, and `extras` fields in the provided message will replace the corresponding fields in the existing message, while null fields will be left unchanged. Requires the **message-update-own** or **message-update-any** [capability](/docs/auth/capabilities).
517537

518538
See [updating and deleting messages: updates](/docs/messages/updates-deletes#update) for more information.
@@ -531,7 +551,7 @@ See [updating and deleting messages: updates](/docs/messages/updates-deletes#upd
531551
Returns a promise which, upon success, will be fulfilled with an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-result) object containing the new version of the message. Upon failure, the promise will be rejected with an [`ErrorInfo`](/docs/api/realtime-sdk/types#error-info) object which explains the error.
532552
</If>
533553

534-
<If lang="java">
554+
<If lang="java, python">
535555
##### Returns
536556

537557
Returns an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-result) object containing the new version of the message.
@@ -547,6 +567,10 @@ Returns an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-res
547567
`UpdateDeleteResult deleteMessage(Message message, MessageOperation operation)`
548568
</If>
549569

570+
<If lang="python">
571+
`UpdateDeleteResult delete_message(message, operation=None, params=dict())`
572+
</If>
573+
550574
Marks a message as deleted by publishing an update with an action of `MESSAGE_DELETE`. This does not remove the message from the server, and the full message history remains accessible. Uses shallow mixin semantics: non-null `name`, `data`, and `extras` fields in the provided message will replace the corresponding fields in the existing message, while null fields will be left unchanged. Requires the **message-delete-own** or **message-delete-any** [capability](/docs/auth/capabilities).
551575

552576
See [updating and deleting messages: deletes](/docs/messages/updates-deletes#delete) for more information.
@@ -565,7 +589,7 @@ See [updating and deleting messages: deletes](/docs/messages/updates-deletes#del
565589
Returns a promise which, upon success, will be fulfilled with an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-result) object containing the new version of the message. Upon failure, the promise will be rejected with an [`ErrorInfo`](/docs/api/realtime-sdk/types#error-info) object which explains the error.
566590
</If>
567591

568-
<If lang="java">
592+
<If lang="java,python">
569593
##### Returns
570594

571595
Returns an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-result) object containing the new version of the message.
@@ -581,6 +605,10 @@ Returns an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-res
581605
`UpdateDeleteResult appendMessage(Message message, MessageOperation operation)`
582606
</If>
583607

608+
<If lang="python">
609+
`UpdateDeleteResult append_message(message, operation=None, params=dict())`
610+
</If>
611+
584612
Appends data to an existing message. The supplied `data` field is appended to the previous message's data, while all other fields (`name`, `extras`) replace the previous values if provided. Requires the **message-update-own** or **message-update-any** [capability](/docs/auth/capabilities).
585613

586614
For publishing a high rate of appends, you typically want to use a realtime client, not a REST client, in order to have message order preservation. See [append ordering](/docs/messages/updates-deletes#append-ordering).
@@ -601,7 +629,7 @@ See [updating and deleting messages: appends](/docs/messages/updates-deletes#app
601629
Returns a promise which, upon success, will be fulfilled with an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-result) object containing the new version of the message. Upon failure, the promise will be rejected with an [`ErrorInfo`](/docs/api/realtime-sdk/types#error-info) object which explains the error.
602630
</If>
603631

604-
<If lang="java">
632+
<If lang="java,python">
605633
##### Returns
606634

607635
Returns an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-result) object containing the new version of the message.
@@ -617,6 +645,10 @@ Returns an [`UpdateDeleteResult`](/docs/api/realtime-sdk/types#update-delete-res
617645
`PaginatedResult<Message> getMessageVersions(String serial, Param[] params)`
618646
</If>
619647

648+
<If lang="python">
649+
`PaginatedResult get_message_versions(serial_or_message, **params)`
650+
</If>
651+
620652
Retrieves all historical versions of a specific message, ordered by version. This includes the original message and all subsequent updates or delete operations. Requires the **history** [capability](/docs/auth/capabilities).
621653

622654
See [updating and deleting messages: versions](/docs/messages/updates-deletes#versions) for more information.
@@ -634,7 +666,7 @@ See [updating and deleting messages: versions](/docs/messages/updates-deletes#ve
634666
Returns a promise which, upon success, will be fulfilled with a [`PaginatedResult`](#paginated-result) object containing an array of [`Message`](/docs/api/realtime-sdk/messages) objects representing all versions of the message. Upon failure, the promise will be rejected with an [`ErrorInfo`](/docs/api/realtime-sdk/types#error-info) object which explains the error.
635667
</If>
636668

637-
<If lang="java">
669+
<If lang="java,python">
638670
##### Returns
639671

640672
On success, the returned [`PaginatedResult`](#paginated-result) encapsulates an array of [`Message`](#message) objects corresponding to the current page of results. [`PaginatedResult`](#paginated-result) supports pagination using [`next`](#paginated-result) and [`first`](#paginated-result) methods.

src/pages/docs/messages/updates-deletes.mdx

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,21 @@ channel.updateMessage(message, operation, new Callback<UpdateDeleteResult>() {
163163
});
164164
updateFuture.get();
165165
```
166+
167+
```python
168+
realtime = AblyRealtime("{{API_KEY}}")
169+
# This assumes there is an 'updates' namespace with a channel rule enabling updates and deletes
170+
channel = realtime.channels.get("updates:example")
171+
172+
# Publish the original message and get its serial from the result
173+
publish_result = await channel.publish("message-name", "original-data")
174+
serial = publish_result.serials[0]
175+
176+
message = Message(data="updated-data", serial=serial)
177+
operation = MessageOperation(description="reason for update")
178+
result = await channel.update_message(message, operation)
179+
print("Message updated")
180+
```
166181
</Code>
167182

168183
#### Returns
@@ -332,6 +347,21 @@ channel.deleteMessage(message, operation, new Callback<UpdateDeleteResult>() {
332347
});
333348
deleteFuture.get();
334349
```
350+
351+
```python
352+
realtime = AblyRealtime("{{API_KEY}}")
353+
# This assumes there is an 'updates' namespace with a channel rule enabling updates and deletes
354+
channel = realtime.channels.get("updates:example")
355+
356+
# Publish the original message and get its serial from the result
357+
publish_result = await channel.publish("message-name", "original-data")
358+
serial = publish_result.serials[0]
359+
360+
message = Message(data="", serial=serial) # clear the previous data
361+
operation = MessageOperation(description="reason for delete")
362+
result = await channel.delete_message(message, operation)
363+
print("Message deleted")
364+
```
335365
</Code>
336366

337367
#### Returns
@@ -480,6 +510,25 @@ appendFuture.get();
480510
// the message in history now has data: "Hello, World!"
481511
```
482512

513+
```python
514+
realtime = AblyRealtime("{{API_KEY}}")
515+
# This assumes there is an 'updates' namespace with a channel rule enabling updates and deletes
516+
channel = realtime.channels.get("updates:example")
517+
518+
# Publish the original message and get its serial from the result
519+
publish_result = await channel.publish("message-name", "Hello")
520+
serial = publish_result.serials[0]
521+
522+
message1 = Message(data=" , ", serial=serial)
523+
channel.append_message(message1)
524+
message2 = Message(data="World", serial=serial)
525+
channel.append_message(message2)
526+
message3 = Message(data="!", serial=serial)
527+
result = await channel.append_message(message3)
528+
529+
# the message in history now has data: "Hello, World!"
530+
```
531+
483532
```swift
484533
import Ably
485534

@@ -609,6 +658,16 @@ String serial = "0123456789-001@abcdefghij:001";
609658

610659
Message message = channel.getMessage(serial);
611660
```
661+
662+
```python
663+
rest = AblyRest("{{API_KEY}}")
664+
channel = rest.channels.get("updates:example")
665+
666+
# Example serial; for example from the `serial` property of a `Message` you previously received
667+
serial = "0123456789-001@abcdefghij:001"
668+
669+
message = await channel.get_message(serial)
670+
```
612671
</Code>
613672

614673
## Get message versions <a id="versions"/>
@@ -664,6 +723,17 @@ String serial = "0123456789-001@abcdefghij:001";
664723
PaginatedResult<Message> page = channel.getMessageVersions(serial);
665724
System.out.println("Found " + page.items().length + " versions");
666725
```
726+
727+
```python
728+
rest = AblyRest("{{API_KEY}}")
729+
channel = rest.channels.get("updates:example")
730+
731+
# Example serial; for example from the `serial` property of a `Message` you previously received
732+
serial = "0123456789-001@abcdefghij:001"
733+
734+
page = await channel.getMessageVersions(serial)
735+
print("Found " + len(page.items) + " versions");
736+
```
667737
</Code>
668738

669739
## Message version structure <a id="version-structure"/>

0 commit comments

Comments
 (0)