@@ -257,6 +257,110 @@ For example:
257
257
except SeamActionAttemptTimeoutError as e:
258
258
print (" Door took too long to unlock" )
259
259
260
+ Pagination
261
+ ~~~~~~~~~~
262
+
263
+ Some Seam API endpoints that return lists of resources support pagination.
264
+ Use the ``SeamPaginator `` class to fetch and process resources across multiple pages.
265
+
266
+ Manually fetch pages with the nextPageCursor
267
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
268
+
269
+ .. code-block :: python
270
+
271
+ from seam import Seam
272
+
273
+ seam = Seam()
274
+
275
+ paginator = seam.create_paginator(seam.connected_accounts.list, {" limit" : 20 })
276
+
277
+ connected_accounts, pagination = paginator.first_page()
278
+
279
+ if pagination.has_next_page:
280
+ more_connected_accounts, _ = paginator.next_page(pagination.next_page_cursor)
281
+
282
+ Resume pagination
283
+ ^^^^^^^^^^^^^^^^^
284
+
285
+ Get the first page on initial load and store the state (e.g., in memory or a file):
286
+
287
+ .. code-block :: python
288
+
289
+ import json
290
+ from seam import Seam
291
+
292
+ seam = Seam()
293
+
294
+ params = {" limit" : 20 }
295
+ paginator = seam.create_paginator(seam.connected_accounts.list, params)
296
+
297
+ connected_accounts, pagination = paginator.first_page()
298
+
299
+ # Example: Store state for later use (e.g., in a file or database)
300
+ pagination_state = {
301
+ " params" : params,
302
+ " next_page_cursor" : pagination.next_page_cursor,
303
+ " has_next_page" : pagination.has_next_page,
304
+ }
305
+ # with open("pagination_state.json", "w") as f:
306
+ # with open("/tmp/seam_connected_accounts_list.json", "w") as f:
307
+ # json.dump(pagination_state, f)
308
+
309
+ Get the next page at a later time using the stored state:
310
+
311
+ .. code-block :: python
312
+
313
+ import json
314
+ from seam import Seam
315
+
316
+ seam = Seam()
317
+
318
+ # Example: Load state from where it was stored
319
+ # with open("/tmp/seam_connected_accounts_list.json", "r") as f:
320
+ # pagination_state = json.load(f)
321
+ # Placeholder for loaded state:
322
+ pagination_state = {
323
+ " params" : {" limit" : 20 },
324
+ " next_page_cursor" : " some_cursor_value" ,
325
+ " has_next_page" : True ,
326
+ }
327
+
328
+
329
+ if pagination_state.get(" has_next_page" ):
330
+ paginator = seam.create_paginator(
331
+ seam.connected_accounts.list, pagination_state[" params" ]
332
+ )
333
+ more_connected_accounts, _ = paginator.next_page(
334
+ pagination_state[" next_page_cursor" ]
335
+ )
336
+
337
+ Iterate over all resources
338
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
339
+
340
+ .. code-block :: python
341
+
342
+ from seam import Seam
343
+
344
+ seam = Seam()
345
+
346
+ paginator = seam.create_paginator(seam.connected_accounts.list, {" limit" : 20 })
347
+
348
+ for account in paginator.flatten():
349
+ print (account.account_type_display_name)
350
+
351
+ Return all resources across all pages as a list
352
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
353
+
354
+ .. code-block :: python
355
+
356
+ from seam import Seam
357
+
358
+ seam = Seam()
359
+
360
+ paginator = seam.create_paginator(seam.connected_accounts.list, {" limit" : 20 })
361
+
362
+ all_connected_accounts = paginator.flatten_to_list()
363
+
260
364
Interacting with Multiple Workspaces
261
365
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
262
366
0 commit comments