You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a5aed1a
Browse filesBrowse the repository at this point in the historyBrowse files
stlc-bot
committed
feat(api): configure page_number pagination for the v3 list endpoints
Copy file name to clipboardExpand all lines: README.md
+61Lines changed: 61 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -139,6 +139,67 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
139
139
140
140
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`.
141
141
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
+
asyncdefmain() -> None:
171
+
all_webhooks = []
172
+
# Iterate through items across all pages, issuing requests as needed.
173
+
asyncfor 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
+
142
203
## Nested params
143
204
144
205
Nested parameters are dictionaries, typed using `TypedDict`, for example:
0 commit comments