|
1 | 1 | # Upgrade / Migration Guide |
2 | 2 |
|
| 3 | +## Version 2.x to 3.0.0 |
| 4 | + |
| 5 | +The 3.0.0 version of ably-python introduces several breaking changes to improve the realtime experience and align the API with the Ably specification. These include: |
| 6 | + |
| 7 | + - The realtime channel publish method now uses WebSocket connection instead of REST |
| 8 | + - `ably.realtime.realtime_channel` module renamed to `ably.realtime.channel` |
| 9 | + - `ChannelOptions` moved to `ably.types.channeloptions` |
| 10 | + - REST publish returns publish result with message serials instead of Response object |
| 11 | + |
| 12 | +### The realtime channel publish method now uses WebSocket |
| 13 | + |
| 14 | +In previous versions, publishing messages on a realtime channel would use the REST API. In version 3.0.0, realtime channels now publish messages over the WebSocket connection, which is more efficient and provides better consistency. |
| 15 | + |
| 16 | +This change is mostly transparent to users, but you should be aware that: |
| 17 | +- Messages are now published through the realtime connection |
| 18 | +- You will receive publish results containing message serials |
| 19 | +- The behavior is now consistent with other Ably SDKs |
| 20 | + |
| 21 | +### Module rename: `ably.realtime.realtime_channel` to `ably.realtime.channel` |
| 22 | + |
| 23 | +If you were importing from `ably.realtime.realtime_channel`, you will need to update your imports: |
| 24 | + |
| 25 | +Example 2.x code: |
| 26 | +```python |
| 27 | +from ably.realtime.realtime_channel import RealtimeChannel |
| 28 | +``` |
| 29 | + |
| 30 | +Example 3.0.0 code: |
| 31 | +```python |
| 32 | +from ably.realtime.channel import RealtimeChannel |
| 33 | +``` |
| 34 | + |
| 35 | +### `ChannelOptions` moved to `ably.types.channeloptions` |
| 36 | + |
| 37 | +The `ChannelOptions` class has been moved to a new location for better organization. |
| 38 | + |
| 39 | +Example 2.x code: |
| 40 | +```python |
| 41 | +from ably.realtime.realtime_channel import ChannelOptions |
| 42 | +``` |
| 43 | + |
| 44 | +Example 3.0.0 code: |
| 45 | +```python |
| 46 | +from ably.types.channeloptions import ChannelOptions |
| 47 | +``` |
| 48 | + |
| 49 | +### REST publish returns publish result with serials |
| 50 | + |
| 51 | +The REST `publish` method now returns a publish result object containing the message serial(s) instead of a raw Response object with `status_code`. |
| 52 | + |
| 53 | +Example 2.x code: |
| 54 | +```python |
| 55 | +response = await channel.publish('event', 'message') |
| 56 | +print(response.status_code) # 201 |
| 57 | +``` |
| 58 | + |
| 59 | +Example 3.0.0 code: |
| 60 | +```python |
| 61 | +result = await channel.publish('event', 'message') |
| 62 | +print(result.serials) # message serials |
| 63 | +``` |
| 64 | + |
| 65 | +### Client options: `endpoint` replaces `environment`, `rest_host`, and `realtime_host` |
| 66 | + |
| 67 | +The `environment`, `rest_host`, and `realtime_host` client options have been deprecated in favor of a single `endpoint` option for better consistency and simplicity. |
| 68 | + |
| 69 | +Example 2.x code: |
| 70 | +```python |
| 71 | +# Using environment |
| 72 | +rest_client = AblyRest(key='api:key', environment='custom') |
| 73 | + |
| 74 | +# Or using rest_host |
| 75 | +rest_client = AblyRest(key='api:key', rest_host='custom.ably.net') |
| 76 | + |
| 77 | +# For realtime |
| 78 | +realtime_client = AblyRealtime(key='api:key', realtime_host='custom.ably.net') |
| 79 | +``` |
| 80 | + |
| 81 | +Example 3.0.0 code: |
| 82 | +```python |
| 83 | +# Using environment |
| 84 | +rest_client = AblyRest(key='api:key', endpoint='custom') |
| 85 | + |
| 86 | +# Using endpoint for REST |
| 87 | +rest_client = AblyRest(key='api:key', endpoint='custom.ably.net') |
| 88 | + |
| 89 | +# Using endpoint for Realtime |
| 90 | +realtime_client = AblyRealtime(key='api:key', endpoint='custom.ably.net') |
| 91 | +``` |
| 92 | + |
3 | 93 | ## Version 1.2.x to 2.x |
4 | 94 |
|
5 | 95 | The 2.0 version of ably-python introduces our first Python realtime client. For guidance on how to use the realtime client, refer to the usage examples in the [README](./README.md). |
|
0 commit comments