Skip to content

Commit e90df1d

Browse files
feat(api): api update
1 parent d0bb085 commit e90df1d

103 files changed

Lines changed: 466 additions & 7415 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.stats.yml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
configured_endpoints: 27
2-
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/unlayer%2Funlayer-077d753eb6d4f805b2f84bf887289213f91c1da5f5a3a4e1e36e1da3689efb46.yml
3-
openapi_spec_hash: b210022cf72d9a38fe1baee599054518
4-
config_hash: 15a2f2b4c1b498b9b314d587d6a331d0
1+
configured_endpoints: 7
2+
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/unlayer%2Funlayer-579dff50df9d2d3be275dc58817917d2efec68100883d139ae7d62908a24e5d6.yml
3+
openapi_spec_hash: 8583074e5ea7cc31410a42c2c4550d7c
4+
config_hash: 3c023f8805c0765c987ddcee566aabef

‎README.md‎

Lines changed: 97 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ client = Unlayer(
3737
environment="stage",
3838
)
3939

40-
full_to_simple = client.convert.full_to_simple.create(
41-
design={"body": {}},
40+
project = client.project.retrieve(
41+
project_id="your-project-id",
4242
)
43-
print(full_to_simple.data)
43+
print(project.data)
4444
```
4545

4646
While you can provide a `access_token` keyword argument,
@@ -65,10 +65,10 @@ client = AsyncUnlayer(
6565

6666

6767
async def main() -> None:
68-
full_to_simple = await client.convert.full_to_simple.create(
69-
design={"body": {}},
68+
project = await client.project.retrieve(
69+
project_id="your-project-id",
7070
)
71-
print(full_to_simple.data)
71+
print(project.data)
7272

7373

7474
asyncio.run(main())
@@ -103,10 +103,10 @@ async def main() -> None:
103103
), # This is the default and can be omitted
104104
http_client=DefaultAioHttpClient(),
105105
) as client:
106-
full_to_simple = await client.convert.full_to_simple.create(
107-
design={"body": {}},
106+
project = await client.project.retrieve(
107+
project_id="your-project-id",
108108
)
109-
print(full_to_simple.data)
109+
print(project.data)
110110

111111

112112
asyncio.run(main())
@@ -121,6 +121,81 @@ Nested request parameters are [TypedDicts](https://docs.python.org/3/library/typ
121121

122122
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`.
123123

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)}")
180+
181+
# Remove `await` for non-async usage.
182+
```
183+
184+
Or just work directly with the returned data:
185+
186+
```python
187+
first_page = await client.project.templates.list(
188+
project_id="your-project-id",
189+
limit=10,
190+
)
191+
192+
print(f"next page cursor: {first_page.next_cursor}") # => "next page cursor: ..."
193+
for template in first_page.data:
194+
print(template.id)
195+
196+
# Remove `await` for non-async usage.
197+
```
198+
124199
## Nested params
125200

126201
Nested parameters are dictionaries, typed using `TypedDict`, for example:
@@ -131,7 +206,7 @@ from unlayer import Unlayer
131206
client = Unlayer()
132207

133208
full_to_simple = client.convert.full_to_simple.create(
134-
design={"body": {}},
209+
design={"body": {"foo": "bar"}},
135210
)
136211
print(full_to_simple.design)
137212
```
@@ -152,8 +227,8 @@ from unlayer import Unlayer
152227
client = Unlayer()
153228

154229
try:
155-
client.convert.full_to_simple.create(
156-
design={"body": {}},
230+
client.project.retrieve(
231+
project_id="your-project-id",
157232
)
158233
except unlayer.APIConnectionError as e:
159234
print("The server could not be reached")
@@ -197,8 +272,8 @@ client = Unlayer(
197272
)
198273

199274
# Or, configure per-request:
200-
client.with_options(max_retries=5).convert.full_to_simple.create(
201-
design={"body": {}},
275+
client.with_options(max_retries=5).project.retrieve(
276+
project_id="your-project-id",
202277
)
203278
```
204279

@@ -222,8 +297,8 @@ client = Unlayer(
222297
)
223298

224299
# Override per-request:
225-
client.with_options(timeout=5.0).convert.full_to_simple.create(
226-
design={"body": {}},
300+
client.with_options(timeout=5.0).project.retrieve(
301+
project_id="your-project-id",
227302
)
228303
```
229304

@@ -265,15 +340,13 @@ The "raw" Response object can be accessed by prefixing `.with_raw_response.` to
265340
from unlayer import Unlayer
266341

267342
client = Unlayer()
268-
response = client.convert.full_to_simple.with_raw_response.create(
269-
design={
270-
"body": {}
271-
},
343+
response = client.project.with_raw_response.retrieve(
344+
project_id="your-project-id",
272345
)
273346
print(response.headers.get('X-My-Header'))
274347

275-
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)
277350
```
278351

279352
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
287360
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.
288361

289362
```python
290-
with client.convert.full_to_simple.with_streaming_response.create(
291-
design={"body": {}},
363+
with client.project.with_streaming_response.retrieve(
364+
project_id="your-project-id",
292365
) as response:
293366
print(response.headers.get("X-My-Header"))
294367

0 commit comments

Comments
 (0)