Skip to content

Commit a5aed1a

Browse files
author
stlc-bot
committed
feat(api): configure page_number pagination for the v3 list endpoints
Stainless-Generated-From: 34bb62535a6f07d17eca9db65162d78c1d8052f1
1 parent 2fdafb6 commit a5aed1a

22 files changed

Lines changed: 705 additions & 474 deletions

‎README.md‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,67 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
139139

140140
Typed requests and responses provide autocomplete and documentation within your editor. If you would like to see type errors in VS Code to help catch bugs earlier, set `python.analysis.typeCheckingMode` to `basic`.
141141

142+
## Pagination
143+
144+
List methods in the Sent API are paginated.
145+
146+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
147+
148+
```python
149+
from sent_dm import Sent
150+
151+
client = Sent()
152+
153+
all_webhooks = []
154+
# Automatically fetches more pages as needed.
155+
for webhook in client.webhooks.list():
156+
# Do something with webhook here
157+
all_webhooks.append(webhook)
158+
print(all_webhooks)
159+
```
160+
161+
Or, asynchronously:
162+
163+
```python
164+
import asyncio
165+
from sent_dm import AsyncSent
166+
167+
client = AsyncSent()
168+
169+
170+
async def main() -> None:
171+
all_webhooks = []
172+
# Iterate through items across all pages, issuing requests as needed.
173+
async for webhook in client.webhooks.list():
174+
all_webhooks.append(webhook)
175+
print(all_webhooks)
176+
177+
178+
asyncio.run(main())
179+
```
180+
181+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
182+
183+
```python
184+
first_page = await client.webhooks.list()
185+
if first_page.has_next_page():
186+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
187+
next_page = await first_page.get_next_page()
188+
print(f"number of items we just fetched: {len(next_page.data.webhooks)}")
189+
190+
# Remove `await` for non-async usage.
191+
```
192+
193+
Or just work directly with the returned data:
194+
195+
```python
196+
first_page = await client.webhooks.list()
197+
for webhook in first_page.data.webhooks:
198+
print(webhook.id)
199+
200+
# Remove `await` for non-async usage.
201+
```
202+
142203
## Nested params
143204

144205
Nested parameters are dictionaries, typed using `TypedDict`, for example:

‎api.md‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ from sent_dm.types import (
1717
TemplateEventPayload,
1818
WebhookEventType,
1919
WebhookResponse,
20-
WebhookListResponse,
2120
WebhookListEventTypesResponse,
2221
WebhookListEventsResponse,
2322
WebhookRotateSecretResponse,
@@ -30,10 +29,10 @@ Methods:
3029
- <code title="post /v3/webhooks">client.webhooks.<a href="./src/sent_dm/resources/webhooks.py">create</a>(\*\*<a href="src/sent_dm/types/webhook_create_params.py">params</a>) -> <a href="./src/sent_dm/types/api_response_webhook.py">APIResponseWebhook</a></code>
3130
- <code title="get /v3/webhooks/{id}">client.webhooks.<a href="./src/sent_dm/resources/webhooks.py">retrieve</a>(id) -> <a href="./src/sent_dm/types/api_response_webhook.py">APIResponseWebhook</a></code>
3231
- <code title="put /v3/webhooks/{id}">client.webhooks.<a href="./src/sent_dm/resources/webhooks.py">update</a>(id, \*\*<a href="src/sent_dm/types/webhook_update_params.py">params</a>) -> <a href="./src/sent_dm/types/api_response_webhook.py">APIResponseWebhook</a></code>
33-
- <code title="get /v3/webhooks">client.webhooks.<a href="./src/sent_dm/resources/webhooks.py">list</a>(\*\*<a href="src/sent_dm/types/webhook_list_params.py">params</a>) -> <a href="./src/sent_dm/types/webhook_list_response.py">WebhookListResponse</a></code>
32+
- <code title="get /v3/webhooks">client.webhooks.<a href="./src/sent_dm/resources/webhooks.py">list</a>(\*\*<a href="src/sent_dm/types/webhook_list_params.py">params</a>) -> <a href="./src/sent_dm/types/webhook_response.py">SyncWebhooksPage[WebhookResponse]</a></code>
3433
- <code title="delete /v3/webhooks/{id}">client.webhooks.<a href="./src/sent_dm/resources/webhooks.py">delete</a>(id) -> None</code>
3534
- <code title="get /v3/webhooks/event-types">client.webhooks.<a href="./src/sent_dm/resources/webhooks.py">list_event_types</a>() -> <a href="./src/sent_dm/types/webhook_list_event_types_response.py">WebhookListEventTypesResponse</a></code>
36-
- <code title="get /v3/webhooks/{id}/events">client.webhooks.<a href="./src/sent_dm/resources/webhooks.py">list_events</a>(id, \*\*<a href="src/sent_dm/types/webhook_list_events_params.py">params</a>) -> <a href="./src/sent_dm/types/webhook_list_events_response.py">WebhookListEventsResponse</a></code>
35+
- <code title="get /v3/webhooks/{id}/events">client.webhooks.<a href="./src/sent_dm/resources/webhooks.py">list_events</a>(id, \*\*<a href="src/sent_dm/types/webhook_list_events_params.py">params</a>) -> <a href="./src/sent_dm/types/webhook_list_events_response.py">SyncWebhookEventsPage[WebhookListEventsResponse]</a></code>
3736
- <code title="post /v3/webhooks/{id}/rotate-secret">client.webhooks.<a href="./src/sent_dm/resources/webhooks.py">rotate_secret</a>(id, \*\*<a href="src/sent_dm/types/webhook_rotate_secret_params.py">params</a>) -> <a href="./src/sent_dm/types/webhook_rotate_secret_response.py">WebhookRotateSecretResponse</a></code>
3837
- <code title="post /v3/webhooks/{id}/test">client.webhooks.<a href="./src/sent_dm/resources/webhooks.py">test</a>(id, \*\*<a href="src/sent_dm/types/webhook_test_params.py">params</a>) -> <a href="./src/sent_dm/types/webhook_test_response.py">WebhookTestResponse</a></code>
3938
- <code title="patch /v3/webhooks/{id}/toggle-status">client.webhooks.<a href="./src/sent_dm/resources/webhooks.py">toggle_status</a>(id, \*\*<a href="src/sent_dm/types/webhook_toggle_status_params.py">params</a>) -> <a href="./src/sent_dm/types/api_response_webhook.py">APIResponseWebhook</a></code>
@@ -71,7 +70,6 @@ from sent_dm.types import (
7170
TemplateFooter,
7271
TemplateHeader,
7372
TemplateVariable,
74-
TemplateListResponse,
7573
)
7674
```
7775

@@ -80,7 +78,7 @@ Methods:
8078
- <code title="post /v3/templates">client.templates.<a href="./src/sent_dm/resources/templates.py">create</a>(\*\*<a href="src/sent_dm/types/template_create_params.py">params</a>) -> <a href="./src/sent_dm/types/api_response_template.py">APIResponseTemplate</a></code>
8179
- <code title="get /v3/templates/{id}">client.templates.<a href="./src/sent_dm/resources/templates.py">retrieve</a>(id) -> <a href="./src/sent_dm/types/api_response_template.py">APIResponseTemplate</a></code>
8280
- <code title="put /v3/templates/{id}">client.templates.<a href="./src/sent_dm/resources/templates.py">update</a>(id, \*\*<a href="src/sent_dm/types/template_update_params.py">params</a>) -> <a href="./src/sent_dm/types/api_response_template.py">APIResponseTemplate</a></code>
83-
- <code title="get /v3/templates">client.templates.<a href="./src/sent_dm/resources/templates.py">list</a>(\*\*<a href="src/sent_dm/types/template_list_params.py">params</a>) -> <a href="./src/sent_dm/types/template_list_response.py">TemplateListResponse</a></code>
81+
- <code title="get /v3/templates">client.templates.<a href="./src/sent_dm/resources/templates.py">list</a>(\*\*<a href="src/sent_dm/types/template_list_params.py">params</a>) -> <a href="./src/sent_dm/types/template.py">SyncTemplatesPage[Template]</a></code>
8482
- <code title="delete /v3/templates/{id}">client.templates.<a href="./src/sent_dm/resources/templates.py">delete</a>(id, \*\*<a href="src/sent_dm/types/template_delete_params.py">params</a>) -> None</code>
8583

8684
# Profiles
@@ -177,7 +175,6 @@ from sent_dm.types import (
177175
APIResponseOfContactMessageSummary,
178176
ContactMessageSummary,
179177
ContactResponse,
180-
ContactListResponse,
181178
)
182179
```
183180

@@ -186,7 +183,7 @@ Methods:
186183
- <code title="post /v3/contacts">client.contacts.<a href="./src/sent_dm/resources/contacts.py">create</a>(\*\*<a href="src/sent_dm/types/contact_create_params.py">params</a>) -> <a href="./src/sent_dm/types/api_response_of_contact.py">APIResponseOfContact</a></code>
187184
- <code title="get /v3/contacts/{id}">client.contacts.<a href="./src/sent_dm/resources/contacts.py">retrieve</a>(id) -> <a href="./src/sent_dm/types/api_response_of_contact.py">APIResponseOfContact</a></code>
188185
- <code title="patch /v3/contacts/{id}">client.contacts.<a href="./src/sent_dm/resources/contacts.py">update</a>(id, \*\*<a href="src/sent_dm/types/contact_update_params.py">params</a>) -> <a href="./src/sent_dm/types/api_response_of_contact.py">APIResponseOfContact</a></code>
189-
- <code title="get /v3/contacts">client.contacts.<a href="./src/sent_dm/resources/contacts.py">list</a>(\*\*<a href="src/sent_dm/types/contact_list_params.py">params</a>) -> <a href="./src/sent_dm/types/contact_list_response.py">ContactListResponse</a></code>
186+
- <code title="get /v3/contacts">client.contacts.<a href="./src/sent_dm/resources/contacts.py">list</a>(\*\*<a href="src/sent_dm/types/contact_list_params.py">params</a>) -> <a href="./src/sent_dm/types/contact_response.py">SyncContactsPage[ContactResponse]</a></code>
190187
- <code title="delete /v3/contacts/{id}">client.contacts.<a href="./src/sent_dm/resources/contacts.py">delete</a>(id, \*\*<a href="src/sent_dm/types/contact_delete_params.py">params</a>) -> None</code>
191188
- <code title="get /v3/contacts/{contactId}/message-summary">client.contacts.<a href="./src/sent_dm/resources/contacts.py">retrieve_message_summary</a>(contact_id) -> <a href="./src/sent_dm/types/api_response_of_contact_message_summary.py">APIResponseOfContactMessageSummary</a></code>
192189

@@ -200,8 +197,8 @@ from sent_dm.types import APIResponseOfConversationMessagesList, ConversationMes
200197

201198
Methods:
202199

203-
- <code title="get /v3/conversations">client.conversations.<a href="./src/sent_dm/resources/conversations.py">list</a>(\*\*<a href="src/sent_dm/types/conversation_list_params.py">params</a>) -> <a href="./src/sent_dm/types/api_response_of_conversation_messages_list.py">APIResponseOfConversationMessagesList</a></code>
204-
- <code title="get /v3/conversations/{id}">client.conversations.<a href="./src/sent_dm/resources/conversations.py">list_messages</a>(id, \*\*<a href="src/sent_dm/types/conversation_list_messages_params.py">params</a>) -> <a href="./src/sent_dm/types/api_response_of_conversation_messages_list.py">APIResponseOfConversationMessagesList</a></code>
200+
- <code title="get /v3/conversations">client.conversations.<a href="./src/sent_dm/resources/conversations.py">list</a>(\*\*<a href="src/sent_dm/types/conversation_list_params.py">params</a>) -> SyncConversationsPage[Message]</code>
201+
- <code title="get /v3/conversations/{id}">client.conversations.<a href="./src/sent_dm/resources/conversations.py">list_messages</a>(id, \*\*<a href="src/sent_dm/types/conversation_list_messages_params.py">params</a>) -> SyncConversationsPage[Message]</code>
205202

206203
# Me
207204

0 commit comments

Comments
 (0)