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
{{ message }}
Repository navigation
Commit e90df1d
Browse filesBrowse the repository at this point in the historyBrowse files
@@ -121,6 +121,81 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
121
121
122
122
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`.
123
123
124
+
## Pagination
125
+
126
+
List methods in the Unlayer API are paginated.
127
+
128
+
This library provides auto-paginating iterators with each list response, so you do not have to request successive pages manually:
129
+
130
+
```python
131
+
from unlayer import Unlayer
132
+
133
+
client = Unlayer()
134
+
135
+
all_templates = []
136
+
# Automatically fetches more pages as needed.
137
+
for template in client.project.templates.list(
138
+
project_id="your-project-id",
139
+
limit=10,
140
+
):
141
+
# Do something with template here
142
+
all_templates.append(template)
143
+
print(all_templates)
144
+
```
145
+
146
+
Or, asynchronously:
147
+
148
+
```python
149
+
import asyncio
150
+
from unlayer import AsyncUnlayer
151
+
152
+
client = AsyncUnlayer()
153
+
154
+
155
+
async def main() -> None:
156
+
all_templates = []
157
+
# Iterate through items across all pages, issuing requests as needed.
158
+
async for template in client.project.templates.list(
159
+
project_id="your-project-id",
160
+
limit=10,
161
+
):
162
+
all_templates.append(template)
163
+
print(all_templates)
164
+
165
+
166
+
asyncio.run(main())
167
+
```
168
+
169
+
Alternatively, you can use the `.has_next_page()`, `.next_page_info()`, or `.get_next_page()` methods for more granular control working with pages:
170
+
171
+
```python
172
+
first_page = await client.project.templates.list(
173
+
project_id="your-project-id",
174
+
limit=10,
175
+
)
176
+
if first_page.has_next_page():
177
+
print(f"will fetch next page using these details: {first_page.next_page_info()}")
178
+
next_page = await first_page.get_next_page()
179
+
print(f"number of items we just fetched: {len(next_page.data)}")
full_to_simple = response.parse() # get the object that `convert.full_to_simple.create()` would have returned
276
-
print(full_to_simple.data)
348
+
project = response.parse() # get the object that `project.retrieve()` would have returned
349
+
print(project.data)
277
350
```
278
351
279
352
These methods return an [`APIResponse`](https://github.com/stainless-sdks/unlayer-python/tree/main/src/unlayer/_response.py) object.
@@ -287,8 +360,8 @@ The above interface eagerly reads the full response body when you make the reque
287
360
To stream the response body, use `.with_streaming_response` instead, which requires a context manager and only reads the response body once you call `.read()`, `.text()`, `.json()`, `.iter_bytes()`, `.iter_text()`, `.iter_lines()` or `.parse()`. In the async client, these are async methods.
288
361
289
362
```python
290
-
with client.convert.full_to_simple.with_streaming_response.create(
291
-
design={"body": {}},
363
+
with client.project.with_streaming_response.retrieve(
0 commit comments