Skip to content

Commit 9b478ad

Browse files
docs: add more examples
1 parent 461ab0b commit 9b478ad

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,71 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
118118

119119
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`.
120120

121+
## Pagination
122+
123+
List methods in the Arcade API are paginated.
124+
125+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
126+
127+
```python
128+
from arcadepy import Arcade
129+
130+
client = Arcade()
131+
132+
all_user_connections = []
133+
# Automatically fetches more pages as needed.
134+
for user_connection in client.admin.user_connections.list():
135+
# Do something with user_connection here
136+
all_user_connections.append(user_connection)
137+
print(all_user_connections)
138+
```
139+
140+
Or, asynchronously:
141+
142+
```python
143+
import asyncio
144+
from arcadepy import AsyncArcade
145+
146+
client = AsyncArcade()
147+
148+
149+
async def main() -> None:
150+
all_user_connections = []
151+
# Iterate through items across all pages, issuing requests as needed.
152+
async for user_connection in client.admin.user_connections.list():
153+
all_user_connections.append(user_connection)
154+
print(all_user_connections)
155+
156+
157+
asyncio.run(main())
158+
```
159+
160+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
161+
162+
```python
163+
first_page = await client.admin.user_connections.list()
164+
if first_page.has_next_page():
165+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
166+
next_page = await first_page.get_next_page()
167+
print(f"number of items we just fetched: {len(next_page.items)}")
168+
169+
# Remove `await` for non-async usage.
170+
```
171+
172+
Or just work directly with the returned data:
173+
174+
```python
175+
first_page = await client.admin.user_connections.list()
176+
177+
print(
178+
f"the current start offset for this page: {first_page.offset}"
179+
) # => "the current start offset for this page: 1"
180+
for user_connection in first_page.items:
181+
print(user_connection.id)
182+
183+
# Remove `await` for non-async usage.
184+
```
185+
121186
## Nested params
122187

123188
Nested parameters are dictionaries, typed using `TypedDict`, for example:

0 commit comments

Comments
 (0)