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
+71Lines changed: 71 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,6 +88,77 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
88
88
89
89
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`.
90
90
91
+
## Pagination
92
+
93
+
List methods in the ZeroEntropy API are paginated.
94
+
95
+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
96
+
97
+
```python
98
+
from zeroentropy import ZeroEntropy
99
+
100
+
client = ZeroEntropy()
101
+
102
+
all_documents = []
103
+
# Automatically fetches more pages as needed.
104
+
for document in client.documents.get_info_list(
105
+
collection_name="example_collection",
106
+
):
107
+
# Do something with document here
108
+
all_documents.append(document)
109
+
print(all_documents)
110
+
```
111
+
112
+
Or, asynchronously:
113
+
114
+
```python
115
+
import asyncio
116
+
from zeroentropy import AsyncZeroEntropy
117
+
118
+
client = AsyncZeroEntropy()
119
+
120
+
121
+
asyncdefmain() -> None:
122
+
all_documents = []
123
+
# Iterate through items across all pages, issuing requests as needed.
124
+
asyncfor document in client.documents.get_info_list(
125
+
collection_name="example_collection",
126
+
):
127
+
all_documents.append(document)
128
+
print(all_documents)
129
+
130
+
131
+
asyncio.run(main())
132
+
```
133
+
134
+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
135
+
136
+
```python
137
+
first_page =await client.documents.get_info_list(
138
+
collection_name="example_collection",
139
+
)
140
+
if first_page.has_next_page():
141
+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
142
+
next_page =await first_page.get_next_page()
143
+
print(f"number of items we just fetched: {len(next_page.documents)}")
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `zeroentropy.APIConnectionError` is raised.
0 commit comments