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
Copy file name to clipboardExpand all lines: README.md
+63Lines changed: 63 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -170,6 +170,69 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
170
170
171
171
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`.
172
172
173
+
## Pagination
174
+
175
+
List methods in the Oz API API are paginated.
176
+
177
+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
178
+
179
+
```python
180
+
from oz_agent_sdk import OzAPI
181
+
182
+
client = OzAPI()
183
+
184
+
all_runs = []
185
+
# Automatically fetches more pages as needed.
186
+
for run in client.agent.runs.list():
187
+
# Do something with run here
188
+
all_runs.append(run)
189
+
print(all_runs)
190
+
```
191
+
192
+
Or, asynchronously:
193
+
194
+
```python
195
+
import asyncio
196
+
from oz_agent_sdk import AsyncOzAPI
197
+
198
+
client = AsyncOzAPI()
199
+
200
+
201
+
asyncdefmain() -> None:
202
+
all_runs = []
203
+
# Iterate through items across all pages, issuing requests as needed.
204
+
asyncfor run in client.agent.runs.list():
205
+
all_runs.append(run)
206
+
print(all_runs)
207
+
208
+
209
+
asyncio.run(main())
210
+
```
211
+
212
+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
213
+
214
+
```python
215
+
first_page =await client.agent.runs.list()
216
+
if first_page.has_next_page():
217
+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
218
+
next_page =await first_page.get_next_page()
219
+
print(f"number of items we just fetched: {len(next_page.runs)}")
0 commit comments