-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpagination.py
More file actions
82 lines (66 loc) · 2.06 KB
/
Copy pathpagination.py
File metadata and controls
82 lines (66 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""Pagination example.
This example demonstrates:
- Manual pagination with offset
- Auto-pagination with search_iter
- Handling large result sets
"""
import asyncio
import os
# TODO: Uncomment after implementation
# from rencom import AsyncRencomClient
async def manual_pagination():
"""Demonstrate manual pagination with offset."""
api_key = os.getenv("RENCOM_API_KEY")
if not api_key:
return
# TODO: Uncomment after implementation
# async with AsyncRencomClient(api_key=api_key) as client:
# page_size = 5
# offset = 0
# page_num = 1
#
# while True:
# print(f"\n=== Page {page_num} ===")
# results = await client.x402.search(
# "api",
# limit=page_size,
# offset=offset
# )
#
# for result in results.results:
# print(f" - {result.resource}")
#
# if not results.has_more:
# print("\nNo more results")
# break
#
# offset += page_size
# page_num += 1
print("TODO: Implement after client is ready")
async def auto_pagination():
"""Demonstrate auto-pagination with search_iter."""
api_key = os.getenv("RENCOM_API_KEY")
if not api_key:
return
# TODO: Uncomment after implementation
# async with AsyncRencomClient(api_key=api_key) as client:
# print("=== Auto-pagination ===")
# count = 0
#
# async for result in client.x402.search_iter("api", limit=5):
# count += 1
# print(f"{count}. {result.resource}")
#
# # Can stop early if needed
# if count >= 20:
# print("\nStopping after 20 results")
# break
print("TODO: Implement after client is ready")
async def main():
"""Run pagination examples."""
print("=== Manual Pagination ===")
await manual_pagination()
print("\n\n=== Auto-Pagination ===")
await auto_pagination()
if __name__ == "__main__":
asyncio.run(main())