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
+62-9Lines changed: 62 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,7 +33,6 @@ client = Docstrange(
33
33
)
34
34
35
35
extract_response = client.extract.sync(
36
-
file=b"raw file contents",
37
36
output_format="markdown",
38
37
)
39
38
print(extract_response.record_id)
@@ -60,7 +59,6 @@ client = AsyncDocstrange(
60
59
61
60
asyncdefmain() -> None:
62
61
extract_response =await client.extract.sync(
63
-
file=b"raw file contents",
64
62
output_format="markdown",
65
63
)
66
64
print(extract_response.record_id)
@@ -97,7 +95,6 @@ async def main() -> None:
97
95
http_client=DefaultAioHttpClient(),
98
96
) as client:
99
97
extract_response =await client.extract.sync(
100
-
file=b"raw file contents",
101
98
output_format="markdown",
102
99
)
103
100
print(extract_response.record_id)
@@ -115,6 +112,67 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
115
112
116
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`.
117
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
+
118
176
## File uploads
119
177
120
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)`.
@@ -126,8 +184,8 @@ from docstrange import Docstrange
126
184
client = Docstrange()
127
185
128
186
client.extract.sync(
129
-
file=Path("/path/to/file"),
130
187
output_format="markdown",
188
+
file=Path("/path/to/file"),
131
189
)
132
190
```
133
191
@@ -150,7 +208,6 @@ client = Docstrange()
150
208
151
209
try:
152
210
client.extract.sync(
153
-
file=b"raw file contents",
154
211
output_format="markdown",
155
212
)
156
213
except docstrange.APIConnectionError as e:
@@ -196,7 +253,6 @@ client = Docstrange(
196
253
197
254
# Or, configure per-request:
198
255
client.with_options(max_retries=5).extract.sync(
199
-
file=b"raw file contents",
200
256
output_format="markdown",
201
257
)
202
258
```
@@ -222,7 +278,6 @@ client = Docstrange(
222
278
223
279
# Override per-request:
224
280
client.with_options(timeout=5.0).extract.sync(
225
-
file=b"raw file contents",
226
281
output_format="markdown",
227
282
)
228
283
```
@@ -266,7 +321,6 @@ from docstrange import Docstrange
266
321
267
322
client = Docstrange()
268
323
response = client.extract.with_raw_response.sync(
269
-
file=b"raw file contents",
270
324
output_format="markdown",
271
325
)
272
326
print(response.headers.get('X-My-Header'))
@@ -287,7 +341,6 @@ To stream the response body, use `.with_streaming_response` instead, which requi
0 commit comments