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
+81Lines changed: 81 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -96,6 +96,87 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
96
96
97
97
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`.
98
98
99
+
## Pagination
100
+
101
+
List methods in the Neptune API V2 API are paginated.
102
+
103
+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
104
+
105
+
```python
106
+
from neptune_api_v2 import NeptuneAPIV2
107
+
108
+
client = NeptuneAPIV2()
109
+
110
+
all_assets = []
111
+
# Automatically fetches more pages as needed.
112
+
for asset in client.assets.get_price_history(
113
+
end=0,
114
+
period="h",
115
+
start=0,
116
+
):
117
+
# Do something with asset here
118
+
all_assets.append(asset)
119
+
print(all_assets)
120
+
```
121
+
122
+
Or, asynchronously:
123
+
124
+
```python
125
+
import asyncio
126
+
from neptune_api_v2 import AsyncNeptuneAPIV2
127
+
128
+
client = AsyncNeptuneAPIV2()
129
+
130
+
131
+
asyncdefmain() -> None:
132
+
all_assets = []
133
+
# Iterate through items across all pages, issuing requests as needed.
134
+
asyncfor asset in client.assets.get_price_history(
135
+
end=0,
136
+
period="h",
137
+
start=0,
138
+
):
139
+
all_assets.append(asset)
140
+
print(all_assets)
141
+
142
+
143
+
asyncio.run(main())
144
+
```
145
+
146
+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
f"the current start offset for this page: {first_page.data.pagination.next_offset}"
173
+
) # => "the current start offset for this page: 1"
174
+
for asset in first_page.data.series:
175
+
print(asset.asset)
176
+
177
+
# Remove `await` for non-async usage.
178
+
```
179
+
99
180
## Handling errors
100
181
101
182
When the library is unable to connect to the API (for example, due to network connection problems or a timeout), a subclass of `neptune_api_v2.APIConnectionError` is raised.
0 commit comments