Skip to content

Commit a293fc1

Browse files
authored
chore: prepare release v2.0 (#137)
1 parent dca4210 commit a293fc1

67 files changed

Lines changed: 421 additions & 273 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ name: Test Python SDK
22
on: [ push ]
33

44
env:
5-
APPLICATION_KEY: ${{ secrets.APPLICATION_KEY }}
6-
APPLICATION_SECRET: ${{ secrets.APPLICATION_SECRET }}
75
AUTH_ORIGIN: ${{ secrets.AUTH_ORIGIN }}
86
CONVERSATION_ORIGIN: ${{ secrets.CONVERSATION_ORIGIN }}
97
DISABLE_SSL: ${{ secrets.DISABLE_SSL }}
@@ -24,9 +22,9 @@ jobs:
2422
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
2523

2624
steps:
27-
- uses: actions/checkout@v3
25+
- uses: actions/checkout@v4
2826
- name: Set up Python ${{ matrix.python-version }}
29-
uses: actions/setup-python@v2
27+
uses: actions/setup-python@v5
3028
with:
3129
python-version: ${{ matrix.python-version }}
3230
- name: Install dependencies
@@ -68,22 +66,17 @@ jobs:
6866
python -m coverage report --skip-empty
6967
7068
- name: Checkout sinch-sdk-mockserver repository
71-
uses: actions/checkout@v3
69+
uses: actions/checkout@v4
7270
with:
7371
repository: sinch/sinch-sdk-mockserver
7472
token: ${{ secrets.PAT_CI }}
7573
fetch-depth: 0
7674
path: sinch-sdk-mockserver
7775

78-
- name: Install Docker Compose
79-
run: |
80-
sudo apt-get update
81-
sudo apt-get install -y docker-compose
82-
8376
- name: Start mock servers with Docker Compose
8477
run: |
8578
cd sinch-sdk-mockserver
86-
docker-compose up -d
79+
docker compose up -d
8780
8881
- name: Copy feature files
8982
run: |
@@ -110,5 +103,3 @@ jobs:
110103
python -m behave tests/e2e/sms/features
111104
python -m behave tests/e2e/conversation/features
112105
python -m behave tests/e2e/number-lookup/features
113-
114-

MIGRATION_GUIDE.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ This guide lists all removed classes and interfaces from V1 and how to migrate t
88

99
> **Note:** Voice and Verification are not yet covered by the new V2 APIs. Support will be added in future releases.
1010
11+
---
12+
1113
## Client Initialization
1214

1315
### Overview
@@ -62,6 +64,8 @@ token_client = SinchClient(
6264
sinch_client.configuration.sms_region = "eu"
6365
```
6466

67+
---
68+
6569
### Conversation Region
6670

6771
**In V1:**
@@ -95,6 +99,8 @@ sinch_client = SinchClient(
9599
sinch_client.configuration.conversation_region = "eu"
96100
```
97101

102+
---
103+
98104
### [`Conversation`](https://github.com/sinch/sinch-sdk-python/tree/main/sinch/domains/conversation)
99105

100106
#### Replacement models
@@ -123,8 +129,8 @@ The Conversation domain API access remains `sinch_client.conversation`; message
123129
| `send()` with `SendConversationMessageRequest` | Use convenience methods: `send_text_message()`, `send_card_message()`, `send_carousel_message()`, `send_choice_message()`, `send_contact_info_message()`, `send_list_message()`, `send_location_message()`, `send_media_message()`, `send_template_message()`<br>Or `send()` with `app_id`, `message` (dict or `SendMessageRequestBodyDict`), and either `contact_id` or `recipient_identities` |
124130
| `get()` with `GetConversationMessageRequest` | `get()` with `message_id: str` parameter |
125131
| `delete()` with `DeleteConversationMessageRequest` | `delete()` with `message_id: str` parameter |
126-
| `list()` with `ListConversationMessagesRequest` | In Progress |
127-
|| **New in V2:** `update()` with `message_id`, `metadata`, and optional `messages_source`|
132+
| `list()` with `ListConversationMessagesRequest` | `list()` with the same fields as keyword arguments (see models table above). V2 adds optional `channel_identity`, `start_time`, `end_time`, `channel`, `direction`. Returns **`Paginator[ConversationMessageResponse]`**: use `.content()` for messages on the current page, `.next_page()` to load the next page, or `.iterator()` to walk every message across all pages. |
133+
|| **New in V2:** `update()` with `message_id`, `metadata`, and optional `messages_source` |
128134

129135
##### Replacement APIs / attributes
130136

@@ -158,7 +164,7 @@ event = handler.parse_event(request_body)
158164

159165
The Conversation HTTP API still expects the JSON field **`callback_url`**. In V2, use the Python parameter / model field `event_destination_target`; it is serialized as `callback_url` on the wire (same pattern as other domains, e.g. SMS).
160166

161-
<br>
167+
---
162168

163169
### [`SMS`](https://github.com/sinch/sinch-sdk-python/tree/main/sinch/domains/sms)
164170

@@ -200,6 +206,7 @@ The Conversation HTTP API still expects the JSON field **`callback_url`**. In V2
200206
#### Replacement APIs
201207

202208
The SMS domain API access remains the same: `sinch.sms.batches` and `sinch.sms.delivery_reports`. However, the underlying models and method signatures have changed.
209+
203210
Note that `sinch.sms.groups` and `sinch.sms.inbounds` are not supported yet and will be available in future minor versions.
204211

205212
##### Batches API
@@ -213,17 +220,17 @@ Note that `sinch.sms.groups` and `sinch.sms.inbounds` are not supported yet and
213220
| `update()` with `UpdateBatchRequest` | Use convenience methods: `update_sms()`, `update_binary()`, `update_mms()`<br>Or `update()` with `UpdateBatchMessageRequest` (Union of `UpdateTextRequestWithBatchId`, `UpdateBinaryRequestWithBatchId`, `UpdateMediaRequestWithBatchId`) |
214221
| `replace()` with `ReplaceBatchRequest` | Use convenience methods: `replace_sms()`, `replace_binary()`, `replace_mms()`<br>Or `replace()` with `ReplaceBatchRequest` (Union of `ReplaceTextRequest`, `ReplaceBinaryRequest`, `ReplaceMediaRequest`) |
215222

216-
<br>
223+
---
217224

218225
##### Delivery Reports API
219226

220227
| Old method | New method in `sms.delivery_reports` |
221228
|------------|-------------------------------------|
222-
| `list()` with `ListSMSDeliveryReportsRequest` | `list()` the parameters `start_date` and `end_date` now accepts both `str` and `datetime` |
229+
| `list()` with `ListSMSDeliveryReportsRequest` | `list()` the parameters `start_date` and `end_date` now accepts both `str` and `datetime` |
223230
| `get_for_batch()` with `GetSMSDeliveryReportForBatchRequest` | `get()` with `batch_id: str` and optional parameters: `report_type`, `status`, `code`, `client_reference` |
224231
| `get_for_number()` with `GetSMSDeliveryReportForNumberRequest` | `get_for_number()` with `batch_id: str` and `recipient: str` parameters |
225232

226-
<br>
233+
---
227234

228235
### [`Numbers` (Virtual Numbers)](https://github.com/sinch/sinch-sdk-python/tree/main/sinch/domains/numbers)
229236

@@ -271,7 +278,6 @@ sinch_client.numbers.event_destinations.update(hmac_secret="your_hmac_secret")
271278

272279
To obtain a Numbers Sinch Events handler: `sinch_client.numbers.sinch_events(callback_secret)` returns a `SinchEvents` instance; `handler.parse_event(request_body)` returns a `NumberSinchEvent`.
273280

274-
275281
```python
276282
# New
277283
from sinch.domains.numbers.sinch_events.v1.events import NumberSinchEvent
@@ -286,7 +292,6 @@ event = handler.parse_event(request_body) # event is a NumberSinchEvent
286292
| **Methods that accept the parameter** | Only `numbers.available.rent_any(..., callback_url=...)` | `numbers.rent(...)`, `numbers.rent_any(...)`, and `numbers.update(...)` accept `event_destination_target` |
287293
| **Parameter name** | `callback_url` | `event_destination_target` |
288294

289-
290295
##### Replacement request/response attributes
291296

292297
| Old | New |

README.md

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ For more information on the Sinch APIs on which this SDK is based, refer to the
2222
- [Prerequisites](#prerequisites)
2323
- [Installation](#installation)
2424
- [Getting started](#getting-started)
25-
- [Logging]()
25+
- [Logging](#logging)
2626

2727
## Prerequisites
2828

@@ -79,41 +79,37 @@ sinch_client = SinchClient(
7979
)
8080
```
8181

82+
### SMS and Conversation regions (V2)
83+
84+
You must set `sms_region` before using the SMS API and `conversation_region` before using the Conversation API—either in the `SinchClient(...)` constructor or on `sinch_client.configuration` before the first call to that product. See [MIGRATION_GUIDE.md](MIGRATION_GUIDE.md) for examples.
85+
8286
## Logging
8387

8488
Logging configuration for this SDK utilizes following hierarchy:
8589
1. If no configuration was provided via `logger_name` or `logger` configurable, SDK will inherit configuration from the root logger with the `Sinch` prefix.
8690
2. If `logger_name` configurable was provided, SDK will use logger related to that name. For example: `myapp.sinch` will inherit configuration from the `myapp` logger.
8791
3. If `logger` (logger instance) configurable was provided, SDK will use that particular logger for all its logging operations.
8892

89-
If all logging returned by this SDK needs to be disabled, usage of `NullHanlder` provided by the standard `logging` module is advised.
93+
If all logging returned by this SDK needs to be disabled, usage of `NullHandler` provided by the standard `logging` module is advised.
9094

9195

9296

9397
## Sample apps
9498

95-
Usage example of the `numbers` domain:
99+
Usage example of the Numbers API via [`VirtualNumbers`](sinch/domains/numbers/virtual_numbers.py) on the client (`sinch_client.numbers`)—`list()` returns your project’s active virtual numbers:
96100

97101
```python
98-
available_numbers = sinch_client.numbers.available.list(
102+
paginator = sinch_client.numbers.list(
99103
region_code="US",
100-
number_type="LOCAL"
104+
number_type="LOCAL",
101105
)
106+
for active_number in paginator.iterator():
107+
print(active_number)
102108
```
103-
Returned values are represented as Python `dataclasses`:
104109

105-
```python
106-
ListAvailableNumbersResponse(
107-
available_numbers=[
108-
Number(
109-
phone_number='+17862045855',
110-
region_code='US',
111-
type='LOCAL',
112-
capability=['SMS', 'VOICE'],
113-
setup_price={'currency_code': 'EUR', 'amount': '0.80'},
114-
monthly_price={'currency_code': 'EUR', 'amount': '0.80'}
115-
...
116-
```
110+
Returned values are [Pydantic](https://docs.pydantic.dev/) model instances (for example [`ActiveNumber`](sinch/domains/numbers/models/v1/response/active_number.py)), including fields such as `phone_number`, `region_code`, `type`, and `capabilities`.
111+
112+
More examples live under [examples/snippets](examples/snippets) on the `main` branch.
117113

118114
### Handling exceptions
119115

@@ -125,9 +121,9 @@ Example for Numbers API:
125121
from sinch.domains.numbers.api.v1.exceptions import NumbersException
126122

127123
try:
128-
nums = sinch_client.numbers.available.list(
124+
paginator = sinch_client.numbers.list(
129125
region_code="US",
130-
number_type="LOCAL"
126+
number_type="LOCAL",
131127
)
132128
except NumbersException as err:
133129
pass
@@ -163,4 +159,4 @@ The transport must be a synchronous implementation.
163159

164160
## License
165161

166-
This project is licensed under the Apache License. See the [LICENSE](license.md) file for the license text.
162+
This project is licensed under the Apache License. See the [LICENSE](LICENSE) file for the license text.

examples/sinch_events/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ package-mode = false
99
python = "^3.9"
1010
python-dotenv = "^1.0.0"
1111
flask = "^3.0.0"
12-
# TODO: Uncomment once v2.0 is released
13-
# sinch = "^2.0.0"
12+
sinch = "^2.0.0"
1413

1514
[build-system]
1615
requires = ["poetry-core"]

examples/snippets/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ All available code snippets are located in subdirectories, structured by feature
5757
To execute a specific snippet, navigate to the appropriate subdirectory and run:
5858

5959
```shell
60-
python run python snippet.py
60+
python snippet.py
6161
```

examples/snippets/conversation/messages/delete/snippet.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
22
Sinch Python Snippet
33
4-
TODO: Update links when v2 is released.
5-
This snippet is available at https://github.com/sinch/sinch-sdk-python/blob/v2.0/docs/snippets/
4+
This snippet is available at https://github.com/sinch/sinch-sdk-python/tree/main/examples/snippets
65
"""
76

87
import os

examples/snippets/conversation/messages/get/snippet.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
22
Sinch Python Snippet
33
4-
TODO: Update links when v2 is released.
5-
This snippet is available at https://github.com/sinch/sinch-sdk-python/blob/v2.0/docs/snippets/
4+
This snippet is available at https://github.com/sinch/sinch-sdk-python/tree/main/examples/snippets
65
"""
76

87
import os

examples/snippets/conversation/messages/list/snippet.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
22
Sinch Python Snippet
33
4-
TODO: Update links when v2 is released.
5-
This snippet is available at https://github.com/sinch/sinch-sdk-python/blob/v2.0/docs/snippets/
4+
This snippet is available at https://github.com/sinch/sinch-sdk-python/tree/main/examples/snippets
65
"""
76

87
import os

examples/snippets/conversation/messages/list_last_messages_by_channel_identity/snippet.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
22
Sinch Python Snippet
33
4-
TODO: Update links when v2 is released.
5-
This snippet is available at https://github.com/sinch/sinch-sdk-python/blob/v2.0/docs/snippets/
4+
This snippet is available at https://github.com/sinch/sinch-sdk-python/tree/main/examples/snippets
65
"""
76

87
import os
@@ -18,7 +17,7 @@
1817
conversation_region=os.environ.get("SINCH_CONVERSATION_REGION") or "MY_CONVERSATION_REGION"
1918
)
2019

21-
# Channel identities to fetch the last message
20+
# The channel identities to fetch the last message for
2221
channel_identities = ["CHANNEL_IDENTITY_1", "CHANNEL_IDENTITY_2"]
2322

2423
messages = sinch_client.conversation.messages.list_last_messages_by_channel_identity(

examples/snippets/conversation/messages/send/snippet.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
"""
22
Sinch Python Snippet
33
4-
TODO: Update links when v2 is released.
5-
This snippet is available at https://github.com/sinch/sinch-sdk-python/blob/v2.0/docs/snippets/
4+
This snippet is available at https://github.com/sinch/sinch-sdk-python/tree/main/examples/snippets
65
"""
76

87
import os
@@ -28,14 +27,17 @@
2827
}
2928
]
3029

30+
# The conversation message payload to send
31+
message = {
32+
"text_message": {
33+
"text": "[Python SDK: Conversation Message] Sample text message",
34+
},
35+
}
36+
3137
response = sinch_client.conversation.messages.send(
3238
app_id=app_id,
33-
message={
34-
"text_message": {
35-
"text": "[Python SDK: Conversation Message] Sample text message"
36-
}
37-
},
38-
recipient_identities=recipient_identities
39+
message=message,
40+
recipient_identities=recipient_identities,
3941
)
4042

4143
print(f"Successfully sent message.\n{response}")

0 commit comments

Comments
 (0)