viewrium 2.0.0__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {viewrium-2.0.0 → viewrium-2.2.0}/.gitignore +1 -0
- viewrium-2.2.0/PKG-INFO +316 -0
- viewrium-2.2.0/README.md +290 -0
- viewrium-2.2.0/pyproject.toml +65 -0
- {viewrium-2.0.0 → viewrium-2.2.0}/src/viewrium/__init__.py +25 -1
- {viewrium-2.0.0 → viewrium-2.2.0}/src/viewrium/_client.py +13 -1
- {viewrium-2.0.0 → viewrium-2.2.0}/src/viewrium/_models.py +154 -5
- {viewrium-2.0.0 → viewrium-2.2.0}/tests/test_client.py +143 -0
- {viewrium-2.0.0 → viewrium-2.2.0}/tests/test_import.py +1 -1
- {viewrium-2.0.0 → viewrium-2.2.0}/uv.lock +1 -1
- viewrium-2.0.0/PKG-INFO +0 -17
- viewrium-2.0.0/README.md +0 -6
- viewrium-2.0.0/pyproject.toml +0 -35
- {viewrium-2.0.0 → viewrium-2.2.0}/.python-version +0 -0
- {viewrium-2.0.0 → viewrium-2.2.0}/LICENSE +0 -0
- {viewrium-2.0.0 → viewrium-2.2.0}/package.json +0 -0
- {viewrium-2.0.0 → viewrium-2.2.0}/src/viewrium/_errors.py +0 -0
- {viewrium-2.0.0 → viewrium-2.2.0}/src/viewrium/py.typed +0 -0
- {viewrium-2.0.0 → viewrium-2.2.0}/turbo.json +0 -0
viewrium-2.2.0/PKG-INFO
ADDED
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: viewrium
|
|
3
|
+
Version: 2.2.0
|
|
4
|
+
Summary: Official Python client for the Viewrium API: AR and 3D product visualization for furniture retailers.
|
|
5
|
+
Project-URL: Homepage, https://www.viewrium.com
|
|
6
|
+
Project-URL: Documentation, https://www.viewrium.com/docs/sdks/python
|
|
7
|
+
Project-URL: API reference, https://www.viewrium.com/docs/api-reference
|
|
8
|
+
Author: Viewrium
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: 3d,api-client,ar,augmented-reality,ecommerce,furniture,glb,product-visualization,sdk,viewrium
|
|
12
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
18
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
19
|
+
Classifier: Topic :: Multimedia :: Graphics :: 3D Modeling
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.12
|
|
23
|
+
Requires-Dist: httpx>=0.28
|
|
24
|
+
Requires-Dist: pydantic>=2.7
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
# viewrium
|
|
28
|
+
|
|
29
|
+
The official Python SDK for the [Viewrium](https://www.viewrium.com) API.
|
|
30
|
+
|
|
31
|
+
Viewrium is AR and 3D product visualization for furniture retailers: it turns product photos, a
|
|
32
|
+
video, a product page URL or an existing 3D file into catalog images, a GLB model and an
|
|
33
|
+
embeddable 3D/AR viewer. This package is a typed, synchronous client for the Viewrium `/v1` REST
|
|
34
|
+
API: create products, review and publish them, export images, manage webhooks and API keys, and
|
|
35
|
+
read usage analytics.
|
|
36
|
+
|
|
37
|
+
- Documentation: https://www.viewrium.com/docs
|
|
38
|
+
- SDK reference: https://www.viewrium.com/docs/sdks/python
|
|
39
|
+
- Dashboard: https://www.viewrium.com
|
|
40
|
+
|
|
41
|
+
## Install
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install viewrium
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or with uv:
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
uv add viewrium
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Requires Python 3.12+. Requests and responses are pydantic v2 models.
|
|
54
|
+
|
|
55
|
+
## Authentication
|
|
56
|
+
|
|
57
|
+
Every request is authenticated with an API key, sent as `Authorization: Bearer <key>`. The SDK
|
|
58
|
+
sets the header for you.
|
|
59
|
+
|
|
60
|
+
- **Secret keys (`sk_`)** are for servers. They can do everything their scopes allow. Never ship
|
|
61
|
+
one to a browser, a mobile app or a public repository. This SDK is meant for secret keys.
|
|
62
|
+
- **Publishable keys (`pk_`)** are safe in a browser but are origin-gated and limited to reading a
|
|
63
|
+
single published product, minting its model ticket and sending analytics beacons. An
|
|
64
|
+
organization with no allowed domains configured has its publishable keys refused everywhere. They power the
|
|
65
|
+
[`<viewrium-viewer>` embed](https://www.viewrium.com/docs/embed), which is how a model is shown on
|
|
66
|
+
a storefront.
|
|
67
|
+
|
|
68
|
+
Create keys in the dashboard under **Settings -> Advanced -> API keys**. A secret key is shown
|
|
69
|
+
exactly once, on create. See [Authentication](https://www.viewrium.com/docs/authentication) for
|
|
70
|
+
scopes.
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
import os
|
|
74
|
+
|
|
75
|
+
from viewrium import Viewrium
|
|
76
|
+
|
|
77
|
+
client = Viewrium(os.environ["VIEWRIUM_API_KEY"])
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
Options:
|
|
81
|
+
|
|
82
|
+
```python
|
|
83
|
+
client = Viewrium(
|
|
84
|
+
"sk_live_...",
|
|
85
|
+
base_url="https://api.viewrium.com", # default
|
|
86
|
+
timeout=30.0, # seconds; the default
|
|
87
|
+
)
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
`products.create` runs the product analysis synchronously, which can take well over 30 seconds.
|
|
91
|
+
Pass a longer `timeout` (for example `timeout=300.0`) to a client that creates products.
|
|
92
|
+
|
|
93
|
+
The client is a context manager that closes its HTTP connection on exit:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
with Viewrium("sk_live_...") as client:
|
|
97
|
+
page = client.products.list()
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Quickstart
|
|
101
|
+
|
|
102
|
+
`products.create` is the single generation entrypoint. Supply exactly one source: `image_urls`,
|
|
103
|
+
`video_url`, `source_url` (a product page) or `model_url` (an existing 3D file). Sources are URLs
|
|
104
|
+
that Viewrium fetches, so they must be publicly reachable.
|
|
105
|
+
|
|
106
|
+
A fresh request **parks**: it returns a `ProductParked` with the plan, the 3D model verdict, the
|
|
107
|
+
price in credits and a `resume_token`, and nothing is written. Posting the token back commits the
|
|
108
|
+
quote, starts the run and returns the `Product`.
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
import os
|
|
112
|
+
import time
|
|
113
|
+
|
|
114
|
+
from viewrium import (
|
|
115
|
+
ModelDimensions,
|
|
116
|
+
ProductCreateRequest,
|
|
117
|
+
ProductDraft,
|
|
118
|
+
ProductParked,
|
|
119
|
+
ProductUpdateRequest,
|
|
120
|
+
Viewrium,
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
with Viewrium(os.environ["VIEWRIUM_API_KEY"], timeout=300.0) as client:
|
|
124
|
+
# 1. Quote
|
|
125
|
+
result = client.products.create(
|
|
126
|
+
ProductCreateRequest(
|
|
127
|
+
image_urls=[
|
|
128
|
+
"https://cdn.example.com/chair-front.jpg",
|
|
129
|
+
"https://cdn.example.com/chair-side.jpg",
|
|
130
|
+
],
|
|
131
|
+
draft=ProductDraft(
|
|
132
|
+
title="Oak dining chair",
|
|
133
|
+
custom_id="sku-oak-chair",
|
|
134
|
+
dimensions=ModelDimensions(height=92),
|
|
135
|
+
),
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
# 2. Commit
|
|
140
|
+
if isinstance(result, ProductParked):
|
|
141
|
+
print(result.cost.total_credits, len(result.plan), result.model.allowed)
|
|
142
|
+
result = client.products.create(ProductCreateRequest(resume_token=result.resume_token))
|
|
143
|
+
assert not isinstance(result, ProductParked) # a resume always commits
|
|
144
|
+
|
|
145
|
+
# 3. Wait for the run (prefer webhooks in production)
|
|
146
|
+
product = result
|
|
147
|
+
while product.display_status == "generating":
|
|
148
|
+
time.sleep(5)
|
|
149
|
+
product = client.products.retrieve(product.id)
|
|
150
|
+
print(product.display_status, product.model.status if product.model else None)
|
|
151
|
+
|
|
152
|
+
# 4. Publish
|
|
153
|
+
client.products.update(product.id, ProductUpdateRequest(published=True))
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
A resume may still edit the `draft` (title, price, tags, dimensions). It may not change the order
|
|
157
|
+
or the overrides: the quote is immutable, and changing what gets generated means a new request.
|
|
158
|
+
A `resume_token` expires after 7 days. A `model_url` source never parks; it commits straight away.
|
|
159
|
+
|
|
160
|
+
Only the fields you set on a request model are sent, so an explicit `None` (for example on an
|
|
161
|
+
image patch, where it clears an override) is different from leaving a field out.
|
|
162
|
+
|
|
163
|
+
See [How generation works](https://www.viewrium.com/docs/generation) and
|
|
164
|
+
[the quote and commit guide](https://www.viewrium.com/docs/guides/quote-and-commit).
|
|
165
|
+
|
|
166
|
+
## Resources
|
|
167
|
+
|
|
168
|
+
| Resource | Methods |
|
|
169
|
+
|---|---|
|
|
170
|
+
| `client.products` | `create`, `list`, `retrieve`, `update`, `delete`, `batch_delete`, `publish`, `tags`, `review`, `update_image`, `update_model`, `rescale`, `create_ticket`, `order`, `export` |
|
|
171
|
+
| `client.api_keys` | `list`, `create`, `revoke` |
|
|
172
|
+
| `client.usage` | `get` |
|
|
173
|
+
| `client.webhooks` | `list`, `create`, `retrieve`, `update`, `delete`, `list_deliveries` |
|
|
174
|
+
| `client.projects` | `list`, `retrieve` |
|
|
175
|
+
| `client.beacon` | `send` |
|
|
176
|
+
| `client` | `health()` |
|
|
177
|
+
|
|
178
|
+
Request models (`ProductCreateRequest`, `ProductDraft`, `ProductUpdateRequest`, `ProductFilters`,
|
|
179
|
+
`WebhookEndpointCreateRequest`, ...), response models (`Product`, `ProductParked`, `ModelPlan`,
|
|
180
|
+
`ProductCost`, `UsageResponse`, ...) and enums (`DisplayStatus`, `ListScope`, `ProductSortField`,
|
|
181
|
+
`SortOrder`, `UsageEventType`, ...) are all importable from the top-level `viewrium` package.
|
|
182
|
+
|
|
183
|
+
### Showing a model: tickets
|
|
184
|
+
|
|
185
|
+
No response carries a URL for a 3D model file - not the product, not a webhook. The only way to a
|
|
186
|
+
model's bytes is a **ticket**: a single-use URL that serves the GLB once and expires within a
|
|
187
|
+
minute (60 s for `view`, 30 s for `ar`). Mint one right before the viewer loads and hand the URL
|
|
188
|
+
straight to the page; never store it.
|
|
189
|
+
|
|
190
|
+
```python
|
|
191
|
+
from viewrium import TicketKind, TicketRequest
|
|
192
|
+
|
|
193
|
+
ticket = client.products.create_ticket(
|
|
194
|
+
product_id,
|
|
195
|
+
# the page that will load the model; one of your allowed domains
|
|
196
|
+
TicketRequest(kind=TicketKind.VIEW, origin="https://shop.example.com"),
|
|
197
|
+
)
|
|
198
|
+
print(ticket.url, ticket.expires_at)
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
A `view` ticket streams only to a request from its `origin`. An `ar` ticket is for Android's Scene
|
|
202
|
+
Viewer, which downloads the file outside the page: mint it on the AR tap. Minting is rate limited
|
|
203
|
+
per IP and per product (429).
|
|
204
|
+
|
|
205
|
+
### Listing and filtering
|
|
206
|
+
|
|
207
|
+
The catalog filters are one `ProductFilters` object, shared by `list`, `tags` and `export`. Paging
|
|
208
|
+
and sorting are keyword arguments on `list`.
|
|
209
|
+
|
|
210
|
+
```python
|
|
211
|
+
from viewrium import DisplayStatus, ProductFilters, ProductSortField, SortOrder
|
|
212
|
+
|
|
213
|
+
page = client.products.list(
|
|
214
|
+
ProductFilters(status=[DisplayStatus.PUBLISHED], tag=["chairs"], q="oak"),
|
|
215
|
+
limit=50,
|
|
216
|
+
sort=ProductSortField.CREATED_AT,
|
|
217
|
+
order=SortOrder.DESC,
|
|
218
|
+
)
|
|
219
|
+
for product in page.data:
|
|
220
|
+
print(product.id, product.title, product.display_status)
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Exporting images
|
|
224
|
+
|
|
225
|
+
`products.export` returns a ZIP of finished images as bytes (the 3D model is never included).
|
|
226
|
+
When more images need finishing than one request can do, it returns a `ProductExportQueued`
|
|
227
|
+
instead: the images are finished in the background, a download link is emailed, and the same call
|
|
228
|
+
returns the archive once they are done.
|
|
229
|
+
|
|
230
|
+
```python
|
|
231
|
+
from viewrium import ProductExportQueued, ProductFilters
|
|
232
|
+
|
|
233
|
+
archive = client.products.export(ProductFilters(tag=["chairs"]))
|
|
234
|
+
if isinstance(archive, ProductExportQueued):
|
|
235
|
+
print("finishing", archive.to_finish, "images; a link goes to", archive.notify_email)
|
|
236
|
+
else:
|
|
237
|
+
with open("catalog.zip", "wb") as f:
|
|
238
|
+
f.write(archive)
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
### Analytics
|
|
242
|
+
|
|
243
|
+
```python
|
|
244
|
+
from datetime import UTC, datetime, timedelta
|
|
245
|
+
|
|
246
|
+
end = datetime.now(UTC)
|
|
247
|
+
usage = client.usage.get(
|
|
248
|
+
start=end - timedelta(days=90),
|
|
249
|
+
end=end,
|
|
250
|
+
granularity="day",
|
|
251
|
+
group_by="product",
|
|
252
|
+
)
|
|
253
|
+
for row in usage.by_product:
|
|
254
|
+
print(row.title, row.totals)
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
Traffic from your own team is excluded unless you pass `include_internal=True`.
|
|
258
|
+
|
|
259
|
+
## Errors
|
|
260
|
+
|
|
261
|
+
Non-2xx responses raise a `ViewriumError` subclass. Every error exposes `status`, `code`,
|
|
262
|
+
`message` and `details` from the API's error envelope.
|
|
263
|
+
|
|
264
|
+
```python
|
|
265
|
+
from viewrium import (
|
|
266
|
+
APIConnectionError,
|
|
267
|
+
AuthenticationError,
|
|
268
|
+
ConflictError,
|
|
269
|
+
PaymentRequiredError,
|
|
270
|
+
ProductCreateRequest,
|
|
271
|
+
RateLimitError,
|
|
272
|
+
ViewriumError,
|
|
273
|
+
)
|
|
274
|
+
|
|
275
|
+
try:
|
|
276
|
+
client.products.create(ProductCreateRequest(image_urls=["https://cdn.example.com/chair.jpg"]))
|
|
277
|
+
except AuthenticationError:
|
|
278
|
+
... # 401: missing or invalid key
|
|
279
|
+
except PaymentRequiredError as err:
|
|
280
|
+
... # 402: the plan does not allow this; err.details["reason"] says why
|
|
281
|
+
except ConflictError:
|
|
282
|
+
... # 409: e.g. a duplicate custom_id or a replayed resume_token
|
|
283
|
+
except RateLimitError:
|
|
284
|
+
... # 429: rate limited, or code "quota_exceeded" when credits run out
|
|
285
|
+
except APIConnectionError:
|
|
286
|
+
... # the request never reached the API, or timed out
|
|
287
|
+
except ViewriumError as err:
|
|
288
|
+
print(err.status, err.code, err.message, err.details)
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
| HTTP | Exception |
|
|
292
|
+
|---|---|
|
|
293
|
+
| 400 | `BadRequestError` |
|
|
294
|
+
| 401 | `AuthenticationError` |
|
|
295
|
+
| 402 | `PaymentRequiredError` |
|
|
296
|
+
| 403 | `PermissionDeniedError` |
|
|
297
|
+
| 404 | `NotFoundError` |
|
|
298
|
+
| 409 | `ConflictError` |
|
|
299
|
+
| 422 | `UnprocessableEntityError` |
|
|
300
|
+
| 429 | `RateLimitError` |
|
|
301
|
+
| 5xx | `ServerError` |
|
|
302
|
+
| none | `APIConnectionError` |
|
|
303
|
+
|
|
304
|
+
The SDK does not retry. On a `RateLimitError`, back off and retry with an exponential delay.
|
|
305
|
+
|
|
306
|
+
## Links
|
|
307
|
+
|
|
308
|
+
- [Quickstart](https://www.viewrium.com/docs/quickstart)
|
|
309
|
+
- [Python SDK reference](https://www.viewrium.com/docs/sdks/python)
|
|
310
|
+
- [Webhooks](https://www.viewrium.com/docs/webhooks)
|
|
311
|
+
- [API reference](https://www.viewrium.com/docs/api-reference)
|
|
312
|
+
- Support: support@viewrium.com
|
|
313
|
+
|
|
314
|
+
## License
|
|
315
|
+
|
|
316
|
+
Apache-2.0
|
viewrium-2.2.0/README.md
ADDED
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
# viewrium
|
|
2
|
+
|
|
3
|
+
The official Python SDK for the [Viewrium](https://www.viewrium.com) API.
|
|
4
|
+
|
|
5
|
+
Viewrium is AR and 3D product visualization for furniture retailers: it turns product photos, a
|
|
6
|
+
video, a product page URL or an existing 3D file into catalog images, a GLB model and an
|
|
7
|
+
embeddable 3D/AR viewer. This package is a typed, synchronous client for the Viewrium `/v1` REST
|
|
8
|
+
API: create products, review and publish them, export images, manage webhooks and API keys, and
|
|
9
|
+
read usage analytics.
|
|
10
|
+
|
|
11
|
+
- Documentation: https://www.viewrium.com/docs
|
|
12
|
+
- SDK reference: https://www.viewrium.com/docs/sdks/python
|
|
13
|
+
- Dashboard: https://www.viewrium.com
|
|
14
|
+
|
|
15
|
+
## Install
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install viewrium
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Or with uv:
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
uv add viewrium
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Requires Python 3.12+. Requests and responses are pydantic v2 models.
|
|
28
|
+
|
|
29
|
+
## Authentication
|
|
30
|
+
|
|
31
|
+
Every request is authenticated with an API key, sent as `Authorization: Bearer <key>`. The SDK
|
|
32
|
+
sets the header for you.
|
|
33
|
+
|
|
34
|
+
- **Secret keys (`sk_`)** are for servers. They can do everything their scopes allow. Never ship
|
|
35
|
+
one to a browser, a mobile app or a public repository. This SDK is meant for secret keys.
|
|
36
|
+
- **Publishable keys (`pk_`)** are safe in a browser but are origin-gated and limited to reading a
|
|
37
|
+
single published product, minting its model ticket and sending analytics beacons. An
|
|
38
|
+
organization with no allowed domains configured has its publishable keys refused everywhere. They power the
|
|
39
|
+
[`<viewrium-viewer>` embed](https://www.viewrium.com/docs/embed), which is how a model is shown on
|
|
40
|
+
a storefront.
|
|
41
|
+
|
|
42
|
+
Create keys in the dashboard under **Settings -> Advanced -> API keys**. A secret key is shown
|
|
43
|
+
exactly once, on create. See [Authentication](https://www.viewrium.com/docs/authentication) for
|
|
44
|
+
scopes.
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import os
|
|
48
|
+
|
|
49
|
+
from viewrium import Viewrium
|
|
50
|
+
|
|
51
|
+
client = Viewrium(os.environ["VIEWRIUM_API_KEY"])
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Options:
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
client = Viewrium(
|
|
58
|
+
"sk_live_...",
|
|
59
|
+
base_url="https://api.viewrium.com", # default
|
|
60
|
+
timeout=30.0, # seconds; the default
|
|
61
|
+
)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
`products.create` runs the product analysis synchronously, which can take well over 30 seconds.
|
|
65
|
+
Pass a longer `timeout` (for example `timeout=300.0`) to a client that creates products.
|
|
66
|
+
|
|
67
|
+
The client is a context manager that closes its HTTP connection on exit:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
with Viewrium("sk_live_...") as client:
|
|
71
|
+
page = client.products.list()
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Quickstart
|
|
75
|
+
|
|
76
|
+
`products.create` is the single generation entrypoint. Supply exactly one source: `image_urls`,
|
|
77
|
+
`video_url`, `source_url` (a product page) or `model_url` (an existing 3D file). Sources are URLs
|
|
78
|
+
that Viewrium fetches, so they must be publicly reachable.
|
|
79
|
+
|
|
80
|
+
A fresh request **parks**: it returns a `ProductParked` with the plan, the 3D model verdict, the
|
|
81
|
+
price in credits and a `resume_token`, and nothing is written. Posting the token back commits the
|
|
82
|
+
quote, starts the run and returns the `Product`.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
import os
|
|
86
|
+
import time
|
|
87
|
+
|
|
88
|
+
from viewrium import (
|
|
89
|
+
ModelDimensions,
|
|
90
|
+
ProductCreateRequest,
|
|
91
|
+
ProductDraft,
|
|
92
|
+
ProductParked,
|
|
93
|
+
ProductUpdateRequest,
|
|
94
|
+
Viewrium,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
with Viewrium(os.environ["VIEWRIUM_API_KEY"], timeout=300.0) as client:
|
|
98
|
+
# 1. Quote
|
|
99
|
+
result = client.products.create(
|
|
100
|
+
ProductCreateRequest(
|
|
101
|
+
image_urls=[
|
|
102
|
+
"https://cdn.example.com/chair-front.jpg",
|
|
103
|
+
"https://cdn.example.com/chair-side.jpg",
|
|
104
|
+
],
|
|
105
|
+
draft=ProductDraft(
|
|
106
|
+
title="Oak dining chair",
|
|
107
|
+
custom_id="sku-oak-chair",
|
|
108
|
+
dimensions=ModelDimensions(height=92),
|
|
109
|
+
),
|
|
110
|
+
)
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
# 2. Commit
|
|
114
|
+
if isinstance(result, ProductParked):
|
|
115
|
+
print(result.cost.total_credits, len(result.plan), result.model.allowed)
|
|
116
|
+
result = client.products.create(ProductCreateRequest(resume_token=result.resume_token))
|
|
117
|
+
assert not isinstance(result, ProductParked) # a resume always commits
|
|
118
|
+
|
|
119
|
+
# 3. Wait for the run (prefer webhooks in production)
|
|
120
|
+
product = result
|
|
121
|
+
while product.display_status == "generating":
|
|
122
|
+
time.sleep(5)
|
|
123
|
+
product = client.products.retrieve(product.id)
|
|
124
|
+
print(product.display_status, product.model.status if product.model else None)
|
|
125
|
+
|
|
126
|
+
# 4. Publish
|
|
127
|
+
client.products.update(product.id, ProductUpdateRequest(published=True))
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
A resume may still edit the `draft` (title, price, tags, dimensions). It may not change the order
|
|
131
|
+
or the overrides: the quote is immutable, and changing what gets generated means a new request.
|
|
132
|
+
A `resume_token` expires after 7 days. A `model_url` source never parks; it commits straight away.
|
|
133
|
+
|
|
134
|
+
Only the fields you set on a request model are sent, so an explicit `None` (for example on an
|
|
135
|
+
image patch, where it clears an override) is different from leaving a field out.
|
|
136
|
+
|
|
137
|
+
See [How generation works](https://www.viewrium.com/docs/generation) and
|
|
138
|
+
[the quote and commit guide](https://www.viewrium.com/docs/guides/quote-and-commit).
|
|
139
|
+
|
|
140
|
+
## Resources
|
|
141
|
+
|
|
142
|
+
| Resource | Methods |
|
|
143
|
+
|---|---|
|
|
144
|
+
| `client.products` | `create`, `list`, `retrieve`, `update`, `delete`, `batch_delete`, `publish`, `tags`, `review`, `update_image`, `update_model`, `rescale`, `create_ticket`, `order`, `export` |
|
|
145
|
+
| `client.api_keys` | `list`, `create`, `revoke` |
|
|
146
|
+
| `client.usage` | `get` |
|
|
147
|
+
| `client.webhooks` | `list`, `create`, `retrieve`, `update`, `delete`, `list_deliveries` |
|
|
148
|
+
| `client.projects` | `list`, `retrieve` |
|
|
149
|
+
| `client.beacon` | `send` |
|
|
150
|
+
| `client` | `health()` |
|
|
151
|
+
|
|
152
|
+
Request models (`ProductCreateRequest`, `ProductDraft`, `ProductUpdateRequest`, `ProductFilters`,
|
|
153
|
+
`WebhookEndpointCreateRequest`, ...), response models (`Product`, `ProductParked`, `ModelPlan`,
|
|
154
|
+
`ProductCost`, `UsageResponse`, ...) and enums (`DisplayStatus`, `ListScope`, `ProductSortField`,
|
|
155
|
+
`SortOrder`, `UsageEventType`, ...) are all importable from the top-level `viewrium` package.
|
|
156
|
+
|
|
157
|
+
### Showing a model: tickets
|
|
158
|
+
|
|
159
|
+
No response carries a URL for a 3D model file - not the product, not a webhook. The only way to a
|
|
160
|
+
model's bytes is a **ticket**: a single-use URL that serves the GLB once and expires within a
|
|
161
|
+
minute (60 s for `view`, 30 s for `ar`). Mint one right before the viewer loads and hand the URL
|
|
162
|
+
straight to the page; never store it.
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from viewrium import TicketKind, TicketRequest
|
|
166
|
+
|
|
167
|
+
ticket = client.products.create_ticket(
|
|
168
|
+
product_id,
|
|
169
|
+
# the page that will load the model; one of your allowed domains
|
|
170
|
+
TicketRequest(kind=TicketKind.VIEW, origin="https://shop.example.com"),
|
|
171
|
+
)
|
|
172
|
+
print(ticket.url, ticket.expires_at)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
A `view` ticket streams only to a request from its `origin`. An `ar` ticket is for Android's Scene
|
|
176
|
+
Viewer, which downloads the file outside the page: mint it on the AR tap. Minting is rate limited
|
|
177
|
+
per IP and per product (429).
|
|
178
|
+
|
|
179
|
+
### Listing and filtering
|
|
180
|
+
|
|
181
|
+
The catalog filters are one `ProductFilters` object, shared by `list`, `tags` and `export`. Paging
|
|
182
|
+
and sorting are keyword arguments on `list`.
|
|
183
|
+
|
|
184
|
+
```python
|
|
185
|
+
from viewrium import DisplayStatus, ProductFilters, ProductSortField, SortOrder
|
|
186
|
+
|
|
187
|
+
page = client.products.list(
|
|
188
|
+
ProductFilters(status=[DisplayStatus.PUBLISHED], tag=["chairs"], q="oak"),
|
|
189
|
+
limit=50,
|
|
190
|
+
sort=ProductSortField.CREATED_AT,
|
|
191
|
+
order=SortOrder.DESC,
|
|
192
|
+
)
|
|
193
|
+
for product in page.data:
|
|
194
|
+
print(product.id, product.title, product.display_status)
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
### Exporting images
|
|
198
|
+
|
|
199
|
+
`products.export` returns a ZIP of finished images as bytes (the 3D model is never included).
|
|
200
|
+
When more images need finishing than one request can do, it returns a `ProductExportQueued`
|
|
201
|
+
instead: the images are finished in the background, a download link is emailed, and the same call
|
|
202
|
+
returns the archive once they are done.
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
from viewrium import ProductExportQueued, ProductFilters
|
|
206
|
+
|
|
207
|
+
archive = client.products.export(ProductFilters(tag=["chairs"]))
|
|
208
|
+
if isinstance(archive, ProductExportQueued):
|
|
209
|
+
print("finishing", archive.to_finish, "images; a link goes to", archive.notify_email)
|
|
210
|
+
else:
|
|
211
|
+
with open("catalog.zip", "wb") as f:
|
|
212
|
+
f.write(archive)
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
### Analytics
|
|
216
|
+
|
|
217
|
+
```python
|
|
218
|
+
from datetime import UTC, datetime, timedelta
|
|
219
|
+
|
|
220
|
+
end = datetime.now(UTC)
|
|
221
|
+
usage = client.usage.get(
|
|
222
|
+
start=end - timedelta(days=90),
|
|
223
|
+
end=end,
|
|
224
|
+
granularity="day",
|
|
225
|
+
group_by="product",
|
|
226
|
+
)
|
|
227
|
+
for row in usage.by_product:
|
|
228
|
+
print(row.title, row.totals)
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
Traffic from your own team is excluded unless you pass `include_internal=True`.
|
|
232
|
+
|
|
233
|
+
## Errors
|
|
234
|
+
|
|
235
|
+
Non-2xx responses raise a `ViewriumError` subclass. Every error exposes `status`, `code`,
|
|
236
|
+
`message` and `details` from the API's error envelope.
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
from viewrium import (
|
|
240
|
+
APIConnectionError,
|
|
241
|
+
AuthenticationError,
|
|
242
|
+
ConflictError,
|
|
243
|
+
PaymentRequiredError,
|
|
244
|
+
ProductCreateRequest,
|
|
245
|
+
RateLimitError,
|
|
246
|
+
ViewriumError,
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
try:
|
|
250
|
+
client.products.create(ProductCreateRequest(image_urls=["https://cdn.example.com/chair.jpg"]))
|
|
251
|
+
except AuthenticationError:
|
|
252
|
+
... # 401: missing or invalid key
|
|
253
|
+
except PaymentRequiredError as err:
|
|
254
|
+
... # 402: the plan does not allow this; err.details["reason"] says why
|
|
255
|
+
except ConflictError:
|
|
256
|
+
... # 409: e.g. a duplicate custom_id or a replayed resume_token
|
|
257
|
+
except RateLimitError:
|
|
258
|
+
... # 429: rate limited, or code "quota_exceeded" when credits run out
|
|
259
|
+
except APIConnectionError:
|
|
260
|
+
... # the request never reached the API, or timed out
|
|
261
|
+
except ViewriumError as err:
|
|
262
|
+
print(err.status, err.code, err.message, err.details)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
| HTTP | Exception |
|
|
266
|
+
|---|---|
|
|
267
|
+
| 400 | `BadRequestError` |
|
|
268
|
+
| 401 | `AuthenticationError` |
|
|
269
|
+
| 402 | `PaymentRequiredError` |
|
|
270
|
+
| 403 | `PermissionDeniedError` |
|
|
271
|
+
| 404 | `NotFoundError` |
|
|
272
|
+
| 409 | `ConflictError` |
|
|
273
|
+
| 422 | `UnprocessableEntityError` |
|
|
274
|
+
| 429 | `RateLimitError` |
|
|
275
|
+
| 5xx | `ServerError` |
|
|
276
|
+
| none | `APIConnectionError` |
|
|
277
|
+
|
|
278
|
+
The SDK does not retry. On a `RateLimitError`, back off and retry with an exponential delay.
|
|
279
|
+
|
|
280
|
+
## Links
|
|
281
|
+
|
|
282
|
+
- [Quickstart](https://www.viewrium.com/docs/quickstart)
|
|
283
|
+
- [Python SDK reference](https://www.viewrium.com/docs/sdks/python)
|
|
284
|
+
- [Webhooks](https://www.viewrium.com/docs/webhooks)
|
|
285
|
+
- [API reference](https://www.viewrium.com/docs/api-reference)
|
|
286
|
+
- Support: support@viewrium.com
|
|
287
|
+
|
|
288
|
+
## License
|
|
289
|
+
|
|
290
|
+
Apache-2.0
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "viewrium"
|
|
3
|
+
version = "2.2.0"
|
|
4
|
+
description = "Official Python client for the Viewrium API: AR and 3D product visualization for furniture retailers."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "Apache-2.0"
|
|
7
|
+
license-files = ["LICENSE"]
|
|
8
|
+
authors = [{ name = "Viewrium" }]
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
keywords = [
|
|
11
|
+
"viewrium",
|
|
12
|
+
"sdk",
|
|
13
|
+
"api-client",
|
|
14
|
+
"3d",
|
|
15
|
+
"ar",
|
|
16
|
+
"augmented-reality",
|
|
17
|
+
"glb",
|
|
18
|
+
"product-visualization",
|
|
19
|
+
"furniture",
|
|
20
|
+
"ecommerce",
|
|
21
|
+
]
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Development Status :: 5 - Production/Stable",
|
|
24
|
+
"Intended Audience :: Developers",
|
|
25
|
+
"Operating System :: OS Independent",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Topic :: Internet :: WWW/HTTP",
|
|
30
|
+
"Topic :: Multimedia :: Graphics :: 3D Modeling",
|
|
31
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
32
|
+
"Typing :: Typed",
|
|
33
|
+
]
|
|
34
|
+
dependencies = ["httpx>=0.28", "pydantic>=2.7"]
|
|
35
|
+
|
|
36
|
+
[project.urls]
|
|
37
|
+
Homepage = "https://www.viewrium.com"
|
|
38
|
+
Documentation = "https://www.viewrium.com/docs/sdks/python"
|
|
39
|
+
"API reference" = "https://www.viewrium.com/docs/api-reference"
|
|
40
|
+
|
|
41
|
+
[dependency-groups]
|
|
42
|
+
dev = ["pytest>=9.1", "ruff>=0.15", "mypy>=2.3"]
|
|
43
|
+
|
|
44
|
+
[build-system]
|
|
45
|
+
requires = ["hatchling"]
|
|
46
|
+
build-backend = "hatchling.build"
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.wheel]
|
|
49
|
+
packages = ["src/viewrium"]
|
|
50
|
+
|
|
51
|
+
[tool.ruff]
|
|
52
|
+
line-length = 100
|
|
53
|
+
target-version = "py312"
|
|
54
|
+
src = ["src"]
|
|
55
|
+
|
|
56
|
+
[tool.ruff.lint]
|
|
57
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
58
|
+
|
|
59
|
+
[tool.mypy]
|
|
60
|
+
python_version = "3.12"
|
|
61
|
+
strict = true
|
|
62
|
+
files = ["src"]
|
|
63
|
+
|
|
64
|
+
[tool.pytest.ini_options]
|
|
65
|
+
testpaths = ["tests"]
|
|
@@ -55,6 +55,15 @@ from ._models import (
|
|
|
55
55
|
ListScope,
|
|
56
56
|
ModelDimensions,
|
|
57
57
|
ModelPlan,
|
|
58
|
+
PaintingDimensionsOf,
|
|
59
|
+
PaintingEdge,
|
|
60
|
+
PaintingInspection,
|
|
61
|
+
PaintingOptions,
|
|
62
|
+
PaintingRebuild,
|
|
63
|
+
PaintingRebuildStatus,
|
|
64
|
+
PaintingRequestedSettings,
|
|
65
|
+
PaintingSettings,
|
|
66
|
+
PaintingUpdate,
|
|
58
67
|
PlannedView,
|
|
59
68
|
Product,
|
|
60
69
|
ProductBatchResponse,
|
|
@@ -98,6 +107,9 @@ from ._models import (
|
|
|
98
107
|
TagCount,
|
|
99
108
|
TagMatch,
|
|
100
109
|
TagsResponse,
|
|
110
|
+
Ticket,
|
|
111
|
+
TicketKind,
|
|
112
|
+
TicketRequest,
|
|
101
113
|
UsageBucket,
|
|
102
114
|
UsageDuration,
|
|
103
115
|
UsageEventType,
|
|
@@ -115,7 +127,7 @@ from ._models import (
|
|
|
115
127
|
WidthAxis,
|
|
116
128
|
)
|
|
117
129
|
|
|
118
|
-
__version__ = "2.
|
|
130
|
+
__version__ = "2.2.0"
|
|
119
131
|
|
|
120
132
|
__all__ = [
|
|
121
133
|
"__version__",
|
|
@@ -156,6 +168,9 @@ __all__ = [
|
|
|
156
168
|
"WebhookEventType",
|
|
157
169
|
"WidthAxis",
|
|
158
170
|
"DimensionUnit",
|
|
171
|
+
"PaintingEdge",
|
|
172
|
+
"PaintingDimensionsOf",
|
|
173
|
+
"PaintingRebuildStatus",
|
|
159
174
|
# requests
|
|
160
175
|
"ProductCreateRequest",
|
|
161
176
|
"ProductDraft",
|
|
@@ -171,6 +186,8 @@ __all__ = [
|
|
|
171
186
|
"ProductModelPatch",
|
|
172
187
|
"ProductFilters",
|
|
173
188
|
"ModelDimensions",
|
|
189
|
+
"PaintingOptions",
|
|
190
|
+
"PaintingUpdate",
|
|
174
191
|
"ShadowOverride",
|
|
175
192
|
"ShadowSilhouette",
|
|
176
193
|
"ShadowContact",
|
|
@@ -199,6 +216,10 @@ __all__ = [
|
|
|
199
216
|
"PlannedView",
|
|
200
217
|
"ModelPlan",
|
|
201
218
|
"ProductCost",
|
|
219
|
+
"PaintingInspection",
|
|
220
|
+
"PaintingSettings",
|
|
221
|
+
"PaintingRebuild",
|
|
222
|
+
"PaintingRequestedSettings",
|
|
202
223
|
"ApiKey",
|
|
203
224
|
"ApiKeyListResponse",
|
|
204
225
|
"ApiKeyCreateResponse",
|
|
@@ -208,6 +229,9 @@ __all__ = [
|
|
|
208
229
|
"UsageResponse",
|
|
209
230
|
"TagCount",
|
|
210
231
|
"TagsResponse",
|
|
232
|
+
"Ticket",
|
|
233
|
+
"TicketKind",
|
|
234
|
+
"TicketRequest",
|
|
211
235
|
"WebhookEndpoint",
|
|
212
236
|
"WebhookEndpointListResponse",
|
|
213
237
|
"WebhookEndpointCreateResponse",
|
|
@@ -48,6 +48,8 @@ from ._models import (
|
|
|
48
48
|
ReviewStatus,
|
|
49
49
|
SortOrder,
|
|
50
50
|
TagsResponse,
|
|
51
|
+
Ticket,
|
|
52
|
+
TicketRequest,
|
|
51
53
|
UsageEventType,
|
|
52
54
|
UsageResponse,
|
|
53
55
|
WebhookDeliveryListResponse,
|
|
@@ -255,7 +257,9 @@ class ProductsResource:
|
|
|
255
257
|
|
|
256
258
|
def update(self, product_id: str, request: ProductUpdateRequest) -> Product:
|
|
257
259
|
"""PATCH /v1/products/{id} - the customer's fields, the user-set status and the
|
|
258
|
-
publish toggle. 409 on a ``custom_id`` another product in the org already holds.
|
|
260
|
+
publish toggle. 409 on a ``custom_id`` another product in the org already holds. On a
|
|
261
|
+
painting, ``painting`` and ``dimensions`` rebuild its model in the background
|
|
262
|
+
(``painting.rebuild``) while the delivered model stays served."""
|
|
259
263
|
return self._client.request(
|
|
260
264
|
"PATCH", f"/v1/products/{product_id}", Product, json=_body(request)
|
|
261
265
|
)
|
|
@@ -315,6 +319,14 @@ class ProductsResource:
|
|
|
315
319
|
"POST", f"/v1/products/{product_id}/model/rescale", Product, json=_body(request)
|
|
316
320
|
)
|
|
317
321
|
|
|
322
|
+
def create_ticket(self, product_id: str, request: TicketRequest) -> Ticket:
|
|
323
|
+
"""POST /v1/products/{id}/tickets - a single-use URL for the product's 3D file, the ONLY
|
|
324
|
+
way to its bytes (no response carries a model file URL). It works once, until
|
|
325
|
+
``expires_at``. With a secret key, pass ``origin``: the page that will load the model."""
|
|
326
|
+
return self._client.request(
|
|
327
|
+
"POST", f"/v1/products/{product_id}/tickets", Ticket, json=_body(request)
|
|
328
|
+
)
|
|
329
|
+
|
|
318
330
|
def order(self, product_id: str, request: ProductOrderRequest) -> ProductOrderParked:
|
|
319
331
|
"""POST /v1/products/{id}/order - order the missing half. It PARKS: commit the
|
|
320
332
|
returned token with ``create``."""
|
|
@@ -163,6 +163,32 @@ class WidthAxis(StrEnum):
|
|
|
163
163
|
Z = "z"
|
|
164
164
|
|
|
165
165
|
|
|
166
|
+
class PaintingEdge(StrEnum):
|
|
167
|
+
"""A painting's edge: ``frame`` (only when the analysis found a frame in the photographs),
|
|
168
|
+
``solid`` (a solid-colour edge, ``edge_color``) or ``stretch`` (the artwork's border pixels
|
|
169
|
+
stretched over the sides)."""
|
|
170
|
+
|
|
171
|
+
FRAME = "frame"
|
|
172
|
+
SOLID = "solid"
|
|
173
|
+
STRETCH = "stretch"
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class PaintingDimensionsOf(StrEnum):
|
|
177
|
+
"""Which rectangle a painting's width x height describe: the ``canvas`` (default) or the
|
|
178
|
+
frame's outer edge (``frame``, only with the ``frame`` edge)."""
|
|
179
|
+
|
|
180
|
+
CANVAS = "canvas"
|
|
181
|
+
FRAME = "frame"
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class PaintingRebuildStatus(StrEnum):
|
|
185
|
+
"""An edit's rebuild: ``running`` or ``failed``. The delivered model stays served during
|
|
186
|
+
and after it."""
|
|
187
|
+
|
|
188
|
+
RUNNING = "running"
|
|
189
|
+
FAILED = "failed"
|
|
190
|
+
|
|
191
|
+
|
|
166
192
|
# --- Requests --------------------------------------------------------------------------------
|
|
167
193
|
|
|
168
194
|
|
|
@@ -174,6 +200,34 @@ class ModelDimensions(_Base):
|
|
|
174
200
|
depth: float | None = None
|
|
175
201
|
|
|
176
202
|
|
|
203
|
+
class PaintingOptions(_Base):
|
|
204
|
+
"""``ProductDraft.painting`` - its PRESENCE selects the painting path: one inspection of
|
|
205
|
+
the photographs, a model-only order at the normal model price, no product images, and a
|
|
206
|
+
product of form ``painting`` that is always wall-mounted.
|
|
207
|
+
|
|
208
|
+
Sizes ride in the draft's ``dimensions`` + ``unit``: ``width`` x ``height`` describe the
|
|
209
|
+
canvas, or the frame's outer edge when ``dimensions_of`` is ``frame``; ``depth`` is the
|
|
210
|
+
slab's and only applies to a ``solid`` or ``stretch`` edge. Every size is optional: with
|
|
211
|
+
none, the canvas's long side is 50 cm and a slab is 2 cm deep. ``edge`` left unset is
|
|
212
|
+
``frame`` when the analysis finds a frame and ``solid`` otherwise.
|
|
213
|
+
"""
|
|
214
|
+
|
|
215
|
+
edge: PaintingEdge | None = None
|
|
216
|
+
edge_color: str = "#FFFFFF"
|
|
217
|
+
dimensions_of: PaintingDimensionsOf = PaintingDimensionsOf.CANVAS
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
class PaintingUpdate(_Base):
|
|
221
|
+
"""``ProductUpdateRequest.painting`` - a painting's settings edit, field by field (an
|
|
222
|
+
omitted field keeps its value). ``frame`` only for a painting ordered with a frame; one
|
|
223
|
+
ordered without can never get one. New sizes go in the request's ``dimensions`` + ``unit``.
|
|
224
|
+
"""
|
|
225
|
+
|
|
226
|
+
edge: PaintingEdge | None = None
|
|
227
|
+
edge_color: str | None = None
|
|
228
|
+
dimensions_of: PaintingDimensionsOf | None = None
|
|
229
|
+
|
|
230
|
+
|
|
177
231
|
class ProductDraft(_Base):
|
|
178
232
|
"""The customer-editable half of a product, sent at park and again at resume.
|
|
179
233
|
|
|
@@ -195,6 +249,7 @@ class ProductDraft(_Base):
|
|
|
195
249
|
dimensions: ModelDimensions | None = None
|
|
196
250
|
unit: DimensionUnit | None = None
|
|
197
251
|
wall_mounted: bool | None = None
|
|
252
|
+
painting: PaintingOptions | None = None
|
|
198
253
|
|
|
199
254
|
|
|
200
255
|
class ProductOrder(_Base):
|
|
@@ -247,7 +302,12 @@ class ProductCreateRequest(_Base):
|
|
|
247
302
|
class ProductUpdateRequest(_Base):
|
|
248
303
|
"""PATCH /v1/products/{id} - the customer's fields, the user-set status (never back to
|
|
249
304
|
``awaiting_review``) and the publish toggle. Dimensions are stored WITHOUT a rescale;
|
|
250
|
-
``products.rescale`` re-applies them to the GLB. 409 on a duplicate ``custom_id``.
|
|
305
|
+
``products.rescale`` re-applies them to the GLB. 409 on a duplicate ``custom_id``.
|
|
306
|
+
|
|
307
|
+
A PAINTING is different: ``painting`` and ``dimensions`` (with ``unit``) are its settings,
|
|
308
|
+
and changing either rebuilds its model in the background (``Product.painting.rebuild``).
|
|
309
|
+
The delivered model stays ready and served meanwhile.
|
|
310
|
+
"""
|
|
251
311
|
|
|
252
312
|
title: str | None = None
|
|
253
313
|
description: str | None = None
|
|
@@ -262,6 +322,7 @@ class ProductUpdateRequest(_Base):
|
|
|
262
322
|
wall_mounted: bool | None = None
|
|
263
323
|
status: ProductStatus | None = None
|
|
264
324
|
published: bool | None = None
|
|
325
|
+
painting: PaintingUpdate | None = None
|
|
265
326
|
|
|
266
327
|
|
|
267
328
|
class ProductPublishRequest(_Base):
|
|
@@ -288,6 +349,23 @@ class ProductRescaleRequest(_Base):
|
|
|
288
349
|
width_axis: WidthAxis | None = None
|
|
289
350
|
|
|
290
351
|
|
|
352
|
+
class TicketKind(StrEnum):
|
|
353
|
+
"""What a model ticket is for: ``view`` (the page itself) or ``ar`` (Android's Scene Viewer,
|
|
354
|
+
which downloads the file outside the page)."""
|
|
355
|
+
|
|
356
|
+
VIEW = "view"
|
|
357
|
+
AR = "ar"
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
class TicketRequest(_Base):
|
|
361
|
+
"""``products.create_ticket`` body. ``origin`` is for a SERVER minting on a page's behalf
|
|
362
|
+
(a secret key): the origin of the page that will load the model, one of your allowed
|
|
363
|
+
domains. A publishable-key ticket is bound to the request's own Origin instead."""
|
|
364
|
+
|
|
365
|
+
kind: TicketKind
|
|
366
|
+
origin: str | None = None
|
|
367
|
+
|
|
368
|
+
|
|
291
369
|
class ProductOrderRequest(_Base):
|
|
292
370
|
"""POST /v1/products/{id}/order - order the missing half (images onto a model-only
|
|
293
371
|
product, or a model onto an images one). It PARKS: the additions and their cost come back
|
|
@@ -493,6 +571,18 @@ class ModelPlan(_Base):
|
|
|
493
571
|
unseen_views: list[str] = Field(default_factory=list)
|
|
494
572
|
|
|
495
573
|
|
|
574
|
+
class PaintingInspection(_Base):
|
|
575
|
+
"""What the painting analysis found: whether a photograph shows the whole artwork front-on
|
|
576
|
+
and unobscured (``usable``), whether it is framed, and why. ``suggested_dimensions_of`` is
|
|
577
|
+
``frame`` only when the piece is framed and its product page's stated size reads as the
|
|
578
|
+
framed size."""
|
|
579
|
+
|
|
580
|
+
usable: bool
|
|
581
|
+
framed: bool
|
|
582
|
+
reason: str
|
|
583
|
+
suggested_dimensions_of: PaintingDimensionsOf = PaintingDimensionsOf.CANVAS
|
|
584
|
+
|
|
585
|
+
|
|
496
586
|
class ProductCost(_Base):
|
|
497
587
|
"""The priced bundle, in CREDITS (1 credit = $0.50): 1 per deliverable image, a flat 10 for
|
|
498
588
|
a model. Internal 3D gap-fills never enter the maths."""
|
|
@@ -528,6 +618,10 @@ class ProductParked(_Base):
|
|
|
528
618
|
cost: ProductCost
|
|
529
619
|
generate_unseen: bool = False
|
|
530
620
|
force_model: bool = False
|
|
621
|
+
#: The painting path only: what the inspection found. A painting with no usable
|
|
622
|
+
#: photograph parks with ``model.allowed`` false and ``model.blocked_by``
|
|
623
|
+
#: ``["painting_unusable"]``, and its token cannot be committed.
|
|
624
|
+
painting: PaintingInspection | None = None
|
|
531
625
|
|
|
532
626
|
|
|
533
627
|
class ProductOrderParked(_Base):
|
|
@@ -594,12 +688,12 @@ class ProductImage(_Base):
|
|
|
594
688
|
|
|
595
689
|
|
|
596
690
|
class ProductModel(_Base):
|
|
597
|
-
"""The product's 3D model row.
|
|
691
|
+
"""The product's 3D model row. It carries NO file URL: the bytes are reached only through a
|
|
692
|
+
single-use ticket, ``products.create_ticket``."""
|
|
598
693
|
|
|
599
694
|
id: str
|
|
600
695
|
status: AssetStatus
|
|
601
696
|
review_status: ReviewStatus = ReviewStatus.PENDING
|
|
602
|
-
glb_url: str | None = None
|
|
603
697
|
thumbnail_url: str | None = None
|
|
604
698
|
scale_factor: float | None = None
|
|
605
699
|
width_axis: WidthAxis | None = None
|
|
@@ -609,6 +703,48 @@ class ProductModel(_Base):
|
|
|
609
703
|
completed_at: datetime | None = None
|
|
610
704
|
|
|
611
705
|
|
|
706
|
+
class PaintingRequestedSettings(_Base):
|
|
707
|
+
"""The settings an edit asked for. Sizes are cm. ``frame_width_cm`` / ``frame_height_cm``
|
|
708
|
+
are set only when the edit was sized by the frame."""
|
|
709
|
+
|
|
710
|
+
edge: PaintingEdge
|
|
711
|
+
edge_color: str
|
|
712
|
+
dimensions_of: PaintingDimensionsOf
|
|
713
|
+
canvas_width_cm: float | None = None
|
|
714
|
+
canvas_height_cm: float | None = None
|
|
715
|
+
depth_cm: float | None = None
|
|
716
|
+
frame_width_cm: float | None = None
|
|
717
|
+
frame_height_cm: float | None = None
|
|
718
|
+
|
|
719
|
+
|
|
720
|
+
class PaintingRebuild(_Base):
|
|
721
|
+
"""An edit's rebuild. The model the product shows - and its dimensions and settings - stay
|
|
722
|
+
the delivered ones while it runs and after it fails; a rebuild that succeeds replaces them
|
|
723
|
+
and is then gone. ``error`` is set when it failed (re-apply the edit to retry)."""
|
|
724
|
+
|
|
725
|
+
status: PaintingRebuildStatus
|
|
726
|
+
requested: PaintingRequestedSettings
|
|
727
|
+
requested_at: datetime | None = None
|
|
728
|
+
error: str | None = None
|
|
729
|
+
|
|
730
|
+
|
|
731
|
+
class PaintingSettings(_Base):
|
|
732
|
+
"""A painting product's settings, the ones the model being SHOWN was built with. Sizes are
|
|
733
|
+
cm. ``canvas_width_cm`` / ``canvas_height_cm`` are null only while a canvas is still to be
|
|
734
|
+
derived from a size stated for the frame; ``depth_cm`` is the slab's and null for a framed
|
|
735
|
+
painting. ``has_frame`` is true when the painting was ordered with a frame, the only way it
|
|
736
|
+
ever has one. ``rebuild`` is an edit's rebuild in progress or failed (null when none)."""
|
|
737
|
+
|
|
738
|
+
edge: PaintingEdge
|
|
739
|
+
edge_color: str
|
|
740
|
+
dimensions_of: PaintingDimensionsOf
|
|
741
|
+
canvas_width_cm: float | None = None
|
|
742
|
+
canvas_height_cm: float | None = None
|
|
743
|
+
depth_cm: float | None = None
|
|
744
|
+
has_frame: bool = False
|
|
745
|
+
rebuild: PaintingRebuild | None = None
|
|
746
|
+
|
|
747
|
+
|
|
612
748
|
class ProductSource(_Base):
|
|
613
749
|
"""One photograph or video the product was analyzed from."""
|
|
614
750
|
|
|
@@ -684,18 +820,31 @@ class Product(ProductSummary):
|
|
|
684
820
|
model: ProductModel | None = None
|
|
685
821
|
warnings: list[ProductWarning] = Field(default_factory=list)
|
|
686
822
|
open_request_count: int = 0
|
|
823
|
+
#: A painting's settings (form ``painting``); null for every other product.
|
|
824
|
+
painting: PaintingSettings | None = None
|
|
687
825
|
|
|
688
826
|
|
|
689
827
|
class PublicProduct(_Base):
|
|
690
828
|
"""What a PUBLISHABLE key receives from ``products.retrieve`` - an explicit allow-list,
|
|
691
829
|
because pk keys ship inside the embed in browser-visible JS. Only a PUBLISHED product with
|
|
692
|
-
a READY model is served at all."""
|
|
830
|
+
a READY model is served at all. The model file is reached through ``products.create_ticket``."""
|
|
693
831
|
|
|
694
832
|
id: str
|
|
695
833
|
title: str
|
|
696
|
-
model_url: str | None = None
|
|
697
834
|
thumbnail_url: str | None = None
|
|
698
835
|
model_status: AssetStatus | None = None
|
|
836
|
+
wall_mounted: bool = False
|
|
837
|
+
painting: PaintingSettings | None = None
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
class Ticket(_Base):
|
|
841
|
+
"""A single-use URL for the product's 3D file (``model/gltf-binary``). It works ONCE, until
|
|
842
|
+
``expires_at`` (60 s for ``view``, 30 s for ``ar``), and a ``view`` ticket only from its bound
|
|
843
|
+
origin. Hand it to the viewer at once; never store it."""
|
|
844
|
+
|
|
845
|
+
url: str
|
|
846
|
+
kind: TicketKind
|
|
847
|
+
expires_at: datetime
|
|
699
848
|
|
|
700
849
|
|
|
701
850
|
class ProductListResponse(_Base):
|
|
@@ -16,7 +16,13 @@ from viewrium import (
|
|
|
16
16
|
DimensionUnit,
|
|
17
17
|
DisplayStatus,
|
|
18
18
|
ListScope,
|
|
19
|
+
ModelDimensions,
|
|
19
20
|
NotFoundError,
|
|
21
|
+
PaintingDimensionsOf,
|
|
22
|
+
PaintingEdge,
|
|
23
|
+
PaintingOptions,
|
|
24
|
+
PaintingRebuildStatus,
|
|
25
|
+
PaintingUpdate,
|
|
20
26
|
PaymentRequiredError,
|
|
21
27
|
Product,
|
|
22
28
|
ProductCreateRequest,
|
|
@@ -29,7 +35,11 @@ from viewrium import (
|
|
|
29
35
|
ProductParked,
|
|
30
36
|
ProductRescaleRequest,
|
|
31
37
|
ProductStatus,
|
|
38
|
+
ProductUpdateRequest,
|
|
39
|
+
PublicProduct,
|
|
32
40
|
ReviewStatus,
|
|
41
|
+
TicketKind,
|
|
42
|
+
TicketRequest,
|
|
33
43
|
UnprocessableEntityError,
|
|
34
44
|
Viewrium,
|
|
35
45
|
ViewriumError,
|
|
@@ -148,6 +158,121 @@ def test_force_model_rides_in_the_overrides() -> None:
|
|
|
148
158
|
}
|
|
149
159
|
|
|
150
160
|
|
|
161
|
+
PAINTING_SETTINGS_JSON = {
|
|
162
|
+
"edge": "solid",
|
|
163
|
+
"edge_color": "#FFFFFF",
|
|
164
|
+
"dimensions_of": "canvas",
|
|
165
|
+
"canvas_width_cm": 50.0,
|
|
166
|
+
"canvas_height_cm": 40.0,
|
|
167
|
+
"depth_cm": 2.0,
|
|
168
|
+
"has_frame": True,
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def test_a_painting_create_sends_its_options_and_parks_an_unusable_photo() -> None:
|
|
173
|
+
parked = {
|
|
174
|
+
**PARKED_JSON,
|
|
175
|
+
"form": "painting",
|
|
176
|
+
"wall_mounted": True,
|
|
177
|
+
"model": {"ordered": True, "allowed": False, "blocked_by": ["painting_unusable"]},
|
|
178
|
+
"cost": {"images": 0, "image_credits": 0, "model_credits": 0, "total_credits": 0},
|
|
179
|
+
"painting": {
|
|
180
|
+
"usable": False,
|
|
181
|
+
"framed": True,
|
|
182
|
+
"reason": "a hand covers the lower left corner",
|
|
183
|
+
"suggested_dimensions_of": "frame",
|
|
184
|
+
},
|
|
185
|
+
}
|
|
186
|
+
client, rec = make_client(httpx.Response(200, json=parked))
|
|
187
|
+
result = client.products.create(
|
|
188
|
+
ProductCreateRequest(
|
|
189
|
+
image_urls=["https://cdn/art.jpg"],
|
|
190
|
+
draft=ProductDraft(
|
|
191
|
+
title="Harbour at dusk",
|
|
192
|
+
dimensions=ModelDimensions(width=60, height=45),
|
|
193
|
+
painting=PaintingOptions(edge=PaintingEdge.FRAME),
|
|
194
|
+
),
|
|
195
|
+
)
|
|
196
|
+
)
|
|
197
|
+
|
|
198
|
+
assert isinstance(result, ProductParked)
|
|
199
|
+
assert result.form == "painting" and result.wall_mounted is True
|
|
200
|
+
assert result.model.blocked_by == ["painting_unusable"]
|
|
201
|
+
assert result.painting is not None
|
|
202
|
+
assert result.painting.usable is False
|
|
203
|
+
assert result.painting.suggested_dimensions_of is PaintingDimensionsOf.FRAME
|
|
204
|
+
assert rec.request is not None
|
|
205
|
+
# Only what was set goes on the wire: the API defaults edge_color and dimensions_of.
|
|
206
|
+
assert json.loads(rec.request.content) == {
|
|
207
|
+
"image_urls": ["https://cdn/art.jpg"],
|
|
208
|
+
"draft": {
|
|
209
|
+
"title": "Harbour at dusk",
|
|
210
|
+
"dimensions": {"width": 60.0, "height": 45.0},
|
|
211
|
+
"painting": {"edge": "frame"},
|
|
212
|
+
},
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def test_a_painting_edit_patches_its_settings_and_reads_the_rebuild() -> None:
|
|
217
|
+
body = {
|
|
218
|
+
**PRODUCT_JSON,
|
|
219
|
+
"form": "painting",
|
|
220
|
+
"wall_mounted": True,
|
|
221
|
+
"painting": {
|
|
222
|
+
**PAINTING_SETTINGS_JSON,
|
|
223
|
+
"rebuild": {
|
|
224
|
+
"status": "running",
|
|
225
|
+
"requested": {
|
|
226
|
+
**PAINTING_SETTINGS_JSON,
|
|
227
|
+
"edge": "stretch",
|
|
228
|
+
"canvas_width_cm": 70.0,
|
|
229
|
+
"canvas_height_cm": 56.0,
|
|
230
|
+
},
|
|
231
|
+
"requested_at": "2026-10-23T10:00:00Z",
|
|
232
|
+
},
|
|
233
|
+
},
|
|
234
|
+
}
|
|
235
|
+
client, rec = make_client(httpx.Response(200, json=body))
|
|
236
|
+
product = client.products.update(
|
|
237
|
+
"p1",
|
|
238
|
+
ProductUpdateRequest(
|
|
239
|
+
painting=PaintingUpdate(edge=PaintingEdge.STRETCH),
|
|
240
|
+
dimensions=ModelDimensions(width=70),
|
|
241
|
+
),
|
|
242
|
+
)
|
|
243
|
+
|
|
244
|
+
assert rec.request is not None
|
|
245
|
+
assert rec.request.method == "PATCH"
|
|
246
|
+
assert json.loads(rec.request.content) == {
|
|
247
|
+
"painting": {"edge": "stretch"},
|
|
248
|
+
"dimensions": {"width": 70.0},
|
|
249
|
+
}
|
|
250
|
+
assert product.painting is not None
|
|
251
|
+
# The shown settings stay the delivered ones while the rebuild runs.
|
|
252
|
+
assert product.painting.edge is PaintingEdge.SOLID
|
|
253
|
+
assert product.painting.rebuild is not None
|
|
254
|
+
assert product.painting.rebuild.status is PaintingRebuildStatus.RUNNING
|
|
255
|
+
assert product.painting.rebuild.requested.edge is PaintingEdge.STRETCH
|
|
256
|
+
assert product.painting.rebuild.requested.frame_width_cm is None # sized by the canvas
|
|
257
|
+
assert product.painting.rebuild.error is None
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
def test_the_public_projection_carries_a_paintings_settings() -> None:
|
|
261
|
+
product = PublicProduct.model_validate(
|
|
262
|
+
{
|
|
263
|
+
"id": "p1",
|
|
264
|
+
"title": "Harbour at dusk",
|
|
265
|
+
"model_status": "ready",
|
|
266
|
+
"wall_mounted": True,
|
|
267
|
+
"painting": PAINTING_SETTINGS_JSON,
|
|
268
|
+
}
|
|
269
|
+
)
|
|
270
|
+
|
|
271
|
+
assert product.painting is not None
|
|
272
|
+
assert product.painting.depth_cm == 2.0
|
|
273
|
+
assert product.painting.rebuild is None
|
|
274
|
+
|
|
275
|
+
|
|
151
276
|
def test_rescale_posts_to_the_products_own_model_and_parses_the_achieved_size() -> None:
|
|
152
277
|
body = {**PRODUCT_JSON, "height": 50.8, "display_unit": "in"}
|
|
153
278
|
client, rec = make_client(httpx.Response(200, json=body))
|
|
@@ -170,6 +295,24 @@ def test_rescale_sends_an_explicit_width_axis() -> None:
|
|
|
170
295
|
assert json.loads(rec.request.content) == {"width": 100.0, "width_axis": "x"}
|
|
171
296
|
|
|
172
297
|
|
|
298
|
+
def test_create_ticket_posts_the_kind_and_origin_and_parses_the_ticket() -> None:
|
|
299
|
+
body = {
|
|
300
|
+
"url": "https://api.viewrium.com/m/t",
|
|
301
|
+
"kind": "ar",
|
|
302
|
+
"expires_at": "2026-10-16T12:00:00Z",
|
|
303
|
+
}
|
|
304
|
+
client, rec = make_client(httpx.Response(200, json=body))
|
|
305
|
+
ticket = client.products.create_ticket(
|
|
306
|
+
"p1", TicketRequest(kind=TicketKind.AR, origin="https://shop.example.com")
|
|
307
|
+
)
|
|
308
|
+
|
|
309
|
+
assert rec.request is not None
|
|
310
|
+
assert str(rec.request.url) == "https://api.viewrium.com/v1/products/p1/tickets"
|
|
311
|
+
assert json.loads(rec.request.content) == {"kind": "ar", "origin": "https://shop.example.com"}
|
|
312
|
+
assert ticket.kind is TicketKind.AR
|
|
313
|
+
assert ticket.url == "https://api.viewrium.com/m/t"
|
|
314
|
+
|
|
315
|
+
|
|
173
316
|
def test_products_list_serializes_the_catalog_filters() -> None:
|
|
174
317
|
body = {"data": [], "total": 0, "limit": 50, "offset": 0}
|
|
175
318
|
client, rec = make_client(httpx.Response(200, json=body))
|
viewrium-2.0.0/PKG-INFO
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.5
|
|
2
|
-
Name: viewrium
|
|
3
|
-
Version: 2.0.0
|
|
4
|
-
Summary: Official Viewrium Python SDK
|
|
5
|
-
License-Expression: Apache-2.0
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Requires-Python: >=3.12
|
|
8
|
-
Requires-Dist: httpx>=0.28
|
|
9
|
-
Requires-Dist: pydantic>=2.7
|
|
10
|
-
Description-Content-Type: text/markdown
|
|
11
|
-
|
|
12
|
-
# viewrium (Python SDK)
|
|
13
|
-
|
|
14
|
-
Published `viewrium` on PyPI. Standalone uv project - `pyproject.toml` is the real config; the
|
|
15
|
-
`package.json` here is only a Turborepo shim (lint/typecheck/test/build via `uv run`).
|
|
16
|
-
|
|
17
|
-
Published by `.github/workflows/publish-sdk-python.yml` (`uv build` + PyPI publish).
|
viewrium-2.0.0/README.md
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
# viewrium (Python SDK)
|
|
2
|
-
|
|
3
|
-
Published `viewrium` on PyPI. Standalone uv project - `pyproject.toml` is the real config; the
|
|
4
|
-
`package.json` here is only a Turborepo shim (lint/typecheck/test/build via `uv run`).
|
|
5
|
-
|
|
6
|
-
Published by `.github/workflows/publish-sdk-python.yml` (`uv build` + PyPI publish).
|
viewrium-2.0.0/pyproject.toml
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
[project]
|
|
2
|
-
name = "viewrium"
|
|
3
|
-
version = "2.0.0"
|
|
4
|
-
description = "Official Viewrium Python SDK"
|
|
5
|
-
readme = "README.md"
|
|
6
|
-
license = "Apache-2.0"
|
|
7
|
-
license-files = ["LICENSE"]
|
|
8
|
-
requires-python = ">=3.12"
|
|
9
|
-
dependencies = ["httpx>=0.28", "pydantic>=2.7"]
|
|
10
|
-
|
|
11
|
-
[dependency-groups]
|
|
12
|
-
dev = ["pytest>=9.1", "ruff>=0.15", "mypy>=2.3"]
|
|
13
|
-
|
|
14
|
-
[build-system]
|
|
15
|
-
requires = ["hatchling"]
|
|
16
|
-
build-backend = "hatchling.build"
|
|
17
|
-
|
|
18
|
-
[tool.hatch.build.targets.wheel]
|
|
19
|
-
packages = ["src/viewrium"]
|
|
20
|
-
|
|
21
|
-
[tool.ruff]
|
|
22
|
-
line-length = 100
|
|
23
|
-
target-version = "py312"
|
|
24
|
-
src = ["src"]
|
|
25
|
-
|
|
26
|
-
[tool.ruff.lint]
|
|
27
|
-
select = ["E", "F", "I", "UP", "B"]
|
|
28
|
-
|
|
29
|
-
[tool.mypy]
|
|
30
|
-
python_version = "3.12"
|
|
31
|
-
strict = true
|
|
32
|
-
files = ["src"]
|
|
33
|
-
|
|
34
|
-
[tool.pytest.ini_options]
|
|
35
|
-
testpaths = ["tests"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|