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
+61Lines changed: 61 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -115,6 +115,67 @@ 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 Docstrange 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 docstrange import Docstrange
126
+
127
+
client = Docstrange()
128
+
129
+
all_results = []
130
+
# Automatically fetches more pages as needed.
131
+
for result in client.extract.results.list():
132
+
# Do something with result here
133
+
all_results.append(result)
134
+
print(all_results)
135
+
```
136
+
137
+
Or, asynchronously:
138
+
139
+
```python
140
+
import asyncio
141
+
from docstrange import AsyncDocstrange
142
+
143
+
client = AsyncDocstrange()
144
+
145
+
146
+
asyncdefmain() -> None:
147
+
all_results = []
148
+
# Iterate through items across all pages, issuing requests as needed.
149
+
asyncfor result in client.extract.results.list():
150
+
all_results.append(result)
151
+
print(all_results)
152
+
153
+
154
+
asyncio.run(main())
155
+
```
156
+
157
+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
158
+
159
+
```python
160
+
first_page =await client.extract.results.list()
161
+
if first_page.has_next_page():
162
+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
163
+
next_page =await first_page.get_next_page()
164
+
print(f"number of items we just fetched: {len(next_page.results)}")
165
+
166
+
# Remove `await` for non-async usage.
167
+
```
168
+
169
+
Or just work directly with the returned data:
170
+
171
+
```python
172
+
first_page =await client.extract.results.list()
173
+
for result in first_page.results:
174
+
print(result)
175
+
176
+
# Remove `await` for non-async usage.
177
+
```
178
+
118
179
## File uploads
119
180
120
181
Request parameters that correspond to file uploads can be passed as `bytes`, or a [`PathLike`](https://docs.python.org/3/library/os.html#os.PathLike) instance or a tuple of `(filename, contents, media type)`.
0 commit comments