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
@@ -112,6 +112,67 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
112
112
113
113
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`.
114
114
115
+
## Pagination
116
+
117
+
List methods in the Docstrange API are paginated.
118
+
119
+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
120
+
121
+
```python
122
+
from docstrange import Docstrange
123
+
124
+
client = Docstrange()
125
+
126
+
all_results = []
127
+
# Automatically fetches more pages as needed.
128
+
for result in client.extract.results.list():
129
+
# Do something with result here
130
+
all_results.append(result)
131
+
print(all_results)
132
+
```
133
+
134
+
Or, asynchronously:
135
+
136
+
```python
137
+
import asyncio
138
+
from docstrange import AsyncDocstrange
139
+
140
+
client = AsyncDocstrange()
141
+
142
+
143
+
asyncdefmain() -> None:
144
+
all_results = []
145
+
# Iterate through items across all pages, issuing requests as needed.
146
+
asyncfor result in client.extract.results.list():
147
+
all_results.append(result)
148
+
print(all_results)
149
+
150
+
151
+
asyncio.run(main())
152
+
```
153
+
154
+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
155
+
156
+
```python
157
+
first_page =await client.extract.results.list()
158
+
if first_page.has_next_page():
159
+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
160
+
next_page =await first_page.get_next_page()
161
+
print(f"number of items we just fetched: {len(next_page.results)}")
162
+
163
+
# Remove `await` for non-async usage.
164
+
```
165
+
166
+
Or just work directly with the returned data:
167
+
168
+
```python
169
+
first_page =await client.extract.results.list()
170
+
for result in first_page.results:
171
+
print(result.record_id)
172
+
173
+
# Remove `await` for non-async usage.
174
+
```
175
+
115
176
## File uploads
116
177
117
178
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