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
+73Lines changed: 73 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,6 +115,79 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
115
115
116
116
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`.
117
117
118
+
## Pagination
119
+
120
+
List methods in the Kernel API are paginated.
121
+
122
+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
123
+
124
+
```python
125
+
from kernel import Kernel
126
+
127
+
client = Kernel()
128
+
129
+
all_deployments = []
130
+
# Automatically fetches more pages as needed.
131
+
for deployment in client.deployments.list(
132
+
app_name="YOUR_APP",
133
+
limit=2,
134
+
):
135
+
# Do something with deployment here
136
+
all_deployments.append(deployment)
137
+
print(all_deployments)
138
+
```
139
+
140
+
Or, asynchronously:
141
+
142
+
```python
143
+
import asyncio
144
+
from kernel import AsyncKernel
145
+
146
+
client = AsyncKernel()
147
+
148
+
149
+
asyncdefmain() -> None:
150
+
all_deployments = []
151
+
# Iterate through items across all pages, issuing requests as needed.
152
+
asyncfor deployment in client.deployments.list(
153
+
app_name="YOUR_APP",
154
+
limit=2,
155
+
):
156
+
all_deployments.append(deployment)
157
+
print(all_deployments)
158
+
159
+
160
+
asyncio.run(main())
161
+
```
162
+
163
+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
164
+
165
+
```python
166
+
first_page =await client.deployments.list(
167
+
app_name="YOUR_APP",
168
+
limit=2,
169
+
)
170
+
if first_page.has_next_page():
171
+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
172
+
next_page =await first_page.get_next_page()
173
+
print(f"number of items we just fetched: {len(next_page.items)}")
174
+
175
+
# Remove `await` for non-async usage.
176
+
```
177
+
178
+
Or just work directly with the returned data:
179
+
180
+
```python
181
+
first_page =await client.deployments.list(
182
+
app_name="YOUR_APP",
183
+
limit=2,
184
+
)
185
+
for deployment in first_page.items:
186
+
print(deployment.id)
187
+
188
+
# Remove `await` for non-async usage.
189
+
```
190
+
118
191
## Nested params
119
192
120
193
Nested parameters are dictionaries, typed using `TypedDict`, for example:
0 commit comments