viewrium 2.3.0__tar.gz → 2.4.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: viewrium
3
- Version: 2.3.0
3
+ Version: 2.4.0
4
4
  Summary: Official Python client for the Viewrium API: AR and 3D product visualization for furniture retailers.
5
5
  Project-URL: Homepage, https://www.viewrium.com
6
6
  Project-URL: Documentation, https://www.viewrium.com/docs/sdks/python
@@ -171,7 +171,6 @@ See [How generation works](https://www.viewrium.com/docs/generation) and
171
171
  | `client.api_keys` | `list`, `create`, `revoke` |
172
172
  | `client.usage` | `get` |
173
173
  | `client.webhooks` | `list`, `create`, `retrieve`, `update`, `delete`, `list_deliveries` |
174
- | `client.projects` | `list`, `retrieve` |
175
174
  | `client.beacon` | `send` |
176
175
  | `client` | `health()` |
177
176
 
@@ -145,7 +145,6 @@ See [How generation works](https://www.viewrium.com/docs/generation) and
145
145
  | `client.api_keys` | `list`, `create`, `revoke` |
146
146
  | `client.usage` | `get` |
147
147
  | `client.webhooks` | `list`, `create`, `retrieve`, `update`, `delete`, `list_deliveries` |
148
- | `client.projects` | `list`, `retrieve` |
149
148
  | `client.beacon` | `send` |
150
149
  | `client` | `health()` |
151
150
 
@@ -8,6 +8,7 @@
8
8
  "build": "uv run python -c \"import viewrium\"",
9
9
  "lint": "uv run ruff check .",
10
10
  "typecheck": "uv run mypy src",
11
- "test": "uv run pytest"
11
+ "test": "uv run pytest",
12
+ "check": "uv run pytest tests/test_schema_drift.py -q"
12
13
  }
13
14
  }
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "viewrium"
3
- version = "2.3.0"
3
+ version = "2.4.0"
4
4
  description = "Official Python client for the Viewrium API: AR and 3D product visualization for furniture retailers."
5
5
  readme = "README.md"
6
6
  license = "Apache-2.0"
@@ -20,7 +20,6 @@ from ._client import (
20
20
  ApiKeysResource,
21
21
  BeaconResource,
22
22
  ProductsResource,
23
- ProjectsResource,
24
23
  UsageResource,
25
24
  Viewrium,
26
25
  WebhooksResource,
@@ -94,8 +93,6 @@ from ._models import (
94
93
  ProductSummary,
95
94
  ProductUpdateRequest,
96
95
  ProductWarning,
97
- Project,
98
- ProjectListResponse,
99
96
  PublicProduct,
100
97
  ReviewStatus,
101
98
  ShadowContact,
@@ -129,7 +126,7 @@ from ._models import (
129
126
  WidthAxis,
130
127
  )
131
128
 
132
- __version__ = "2.3.0"
129
+ __version__ = "2.4.0"
133
130
 
134
131
  __all__ = [
135
132
  "__version__",
@@ -139,7 +136,6 @@ __all__ = [
139
136
  "ApiKeysResource",
140
137
  "UsageResource",
141
138
  "WebhooksResource",
142
- "ProjectsResource",
143
139
  "BeaconResource",
144
140
  # errors
145
141
  "ViewriumError",
@@ -241,7 +237,5 @@ __all__ = [
241
237
  "WebhookEndpointCreateResponse",
242
238
  "WebhookDelivery",
243
239
  "WebhookDeliveryListResponse",
244
- "Project",
245
- "ProjectListResponse",
246
240
  "HealthResponse",
247
241
  ]
@@ -3,7 +3,7 @@
3
3
  Method shapes mirror ``@viewrium/sdk`` (one ``products.create`` entrypoint, ``products.list`` /
4
4
  ``retrieve`` / ``retrieve_by_custom_id`` / ``update`` / ``delete`` / ``batch_delete`` /
5
5
  ``publish`` / ``tags`` / ``review`` / ``update_image`` / ``update_model`` / ``rescale`` /
6
- ``order`` / ``export``, plus ``api_keys``, ``usage``, ``webhooks``, ``projects``, ``beacon``).
6
+ ``order`` / ``export``, plus ``api_keys``, ``usage``, ``webhooks``, ``beacon``).
7
7
  Auth is an ``sk_`` secret key (or ``pk_`` publishable key) sent as ``Authorization: Bearer``.
8
8
  """
9
9
 
@@ -43,8 +43,6 @@ from ._models import (
43
43
  ProductReviewResponse,
44
44
  ProductSortField,
45
45
  ProductUpdateRequest,
46
- Project,
47
- ProjectListResponse,
48
46
  ReviewStatus,
49
47
  SortOrder,
50
48
  TagsResponse,
@@ -139,7 +137,6 @@ class Viewrium:
139
137
  self.api_keys = ApiKeysResource(self)
140
138
  self.usage = UsageResource(self)
141
139
  self.webhooks = WebhooksResource(self)
142
- self.projects = ProjectsResource(self)
143
140
  self.beacon = BeaconResource(self)
144
141
 
145
142
  def health(self) -> HealthResponse:
@@ -335,6 +332,17 @@ class ProductsResource:
335
332
  "POST", f"/v1/products/{product_id}/tickets", Ticket, json=_body(request)
336
333
  )
337
334
 
335
+ def qr(self, product_id: str, *, guide: bool = False, size: int = 1024) -> bytes:
336
+ """GET /v1/products/{id}/qr - the product's QR code as a square PNG, ``size`` px on a
337
+ side (256-2048), as bytes. The code encodes the product's ``viewer_url`` and carries the
338
+ Viewrium mark. ``guide=True`` renders the whole "View in your room" card with its three
339
+ steps; the default is the minimal "View in your room" + code + "Powered by Viewrium".
340
+ Answered before the product is published too, but the link opens only once it is."""
341
+ params: Params = {"guide": guide, "size": size}
342
+ return self._client.request_bytes(
343
+ "GET", f"/v1/products/{product_id}/qr", params=params
344
+ ).content
345
+
338
346
  def order(self, product_id: str, request: ProductOrderRequest) -> ProductOrderParked:
339
347
  """POST /v1/products/{id}/order - order the missing half. It PARKS: commit the
340
348
  returned token with ``create``."""
@@ -400,7 +408,6 @@ class UsageResource:
400
408
  org_id: str | None = None,
401
409
  scope: ListScope | None = None,
402
410
  product_id: str | None = None,
403
- project_id: str | None = None,
404
411
  model_id: str | None = None,
405
412
  event_type: UsageEventType | None = None,
406
413
  granularity: Literal["hour", "day"] | None = None,
@@ -411,7 +418,7 @@ class UsageResource:
411
418
 
412
419
  Scope: one org (``org_id``, or the principal's only org), every org a session reaches
413
420
  (``scope=ListScope.ALL``), or one product (``product_id``, which needs no ``org_id``).
414
- ``project_id`` and ``model_id`` are the v1 scan-era filters.
421
+ ``model_id`` is the v1 scan-era filter.
415
422
 
416
423
  ``start`` / ``end`` are arbitrary - any window, not a preset - and default to the last
417
424
  30 days. ``granularity`` buckets by hour or day. Org-internal traffic (an org's own
@@ -429,7 +436,6 @@ class UsageResource:
429
436
  "org_id": org_id,
430
437
  "scope": scope,
431
438
  "product_id": product_id,
432
- "project_id": project_id,
433
439
  "model_id": model_id,
434
440
  "event_type": event_type,
435
441
  "granularity": granularity,
@@ -475,17 +481,6 @@ class WebhooksResource:
475
481
  )
476
482
 
477
483
 
478
- class ProjectsResource:
479
- def __init__(self, client: Viewrium) -> None:
480
- self._client = client
481
-
482
- def list(self) -> ProjectListResponse:
483
- return self._client.request("GET", "/v1/projects", ProjectListResponse)
484
-
485
- def retrieve(self, project_id: str) -> Project:
486
- return self._client.request("GET", f"/v1/projects/{project_id}", Project)
487
-
488
-
489
484
  class BeaconResource:
490
485
  def __init__(self, client: Viewrium) -> None:
491
486
  self._client = client
@@ -135,14 +135,25 @@ class UsageEventType(StrEnum):
135
135
 
136
136
 
137
137
  class WebhookEventType(StrEnum):
138
- """``product.completed`` / ``product.failed`` are the product run's two endings and the
139
- events the pipeline fires today. ``model.ready`` / ``model.failed`` are the scan-era
140
- names, still subscribable, no longer dispatched."""
138
+ """The events an endpoint subscribes to. Every product event's ``data`` is the product's
139
+ public snapshot plus the event's own fields; ``product.deleted`` carries only ``id`` and
140
+ ``custom_id``, ``export.ready`` only ids and counts. No payload carries a model file URL.
141
+
142
+ ``model.ready`` / ``model.failed`` are DEPRECATED scan-era names: still accepted on an
143
+ endpoint, never sent."""
141
144
 
142
145
  MODEL_READY = "model.ready"
143
146
  MODEL_FAILED = "model.failed"
147
+ PRODUCT_CREATED = "product.created"
148
+ PRODUCT_GENERATING = "product.generating"
144
149
  PRODUCT_COMPLETED = "product.completed"
145
150
  PRODUCT_FAILED = "product.failed"
151
+ PRODUCT_REVIEWED = "product.reviewed"
152
+ PRODUCT_PUBLISHED = "product.published"
153
+ PRODUCT_UNPUBLISHED = "product.unpublished"
154
+ PRODUCT_UPDATED = "product.updated"
155
+ PRODUCT_DELETED = "product.deleted"
156
+ EXPORT_READY = "export.ready"
146
157
 
147
158
 
148
159
  class DimensionUnit(StrEnum):
@@ -497,9 +508,8 @@ class ProductFilters(_Base):
497
508
 
498
509
  class ApiKeyCreateRequest(_Base):
499
510
  key_type: KeyType
500
- # Session-created keys bind to an org (F-1.4); an sk key implies both from itself.
511
+ # Session-created keys bind to an org.
501
512
  org_id: str | None = None
502
- project_id: str | None = None
503
513
  name: str | None = None
504
514
  scopes: list[str] = Field(default_factory=list)
505
515
 
@@ -509,7 +519,6 @@ class WebhookEndpointCreateRequest(_Base):
509
519
  events: list[WebhookEventType]
510
520
  description: str | None = None
511
521
  org_id: str | None = None
512
- project_id: str | None = None
513
522
 
514
523
 
515
524
  class WebhookEndpointUpdateRequest(_Base):
@@ -821,6 +830,9 @@ class ProductSummary(_Base):
821
830
  owner: ProductOwner | None = None
822
831
  created_at: datetime
823
832
  updated_at: datetime | None = None
833
+ #: The product's hosted viewer page - what its QR code (``products.qr``) encodes. It opens
834
+ #: only while the product is published.
835
+ viewer_url: str | None = None
824
836
 
825
837
 
826
838
  class Product(ProductSummary):
@@ -885,9 +897,9 @@ class ProductListResponse(_Base):
885
897
  class ProductBatchResponse(_Base):
886
898
  """Per-id outcome; 200 even when some ids were missing."""
887
899
 
888
- affected: list[str] = Field(default_factory=list)
889
- not_found: list[str] = Field(default_factory=list)
890
- forbidden: list[str] = Field(default_factory=list)
900
+ affected: list[str]
901
+ not_found: list[str]
902
+ forbidden: list[str]
891
903
 
892
904
 
893
905
  class ProductReviewResponse(_Base):
@@ -910,9 +922,7 @@ class ProductExportQueued(_Base):
910
922
 
911
923
  class ApiKey(_Base):
912
924
  id: str
913
- # F-1.4: a key binds to an org; project_id is null on every key issued without one.
914
- org_id: str | None = None
915
- project_id: str | None = None
925
+ org_id: str | None = None # a key binds to its org
916
926
  key_type: KeyType
917
927
  key_prefix: str
918
928
  name: str | None = None
@@ -965,15 +975,15 @@ class UsageProductTotals(_Base):
965
975
 
966
976
  product_id: str
967
977
  title: str | None = None
968
- totals: dict[str, int] = Field(default_factory=dict)
978
+ totals: dict[str, int]
969
979
 
970
980
 
971
981
  class UsageResponse(_Base):
972
982
  start: datetime
973
983
  end: datetime
974
984
  granularity: Literal["hour", "day"]
975
- buckets: list[UsageBucket] = Field(default_factory=list)
976
- totals: dict[str, int] = Field(default_factory=dict)
985
+ buckets: list[UsageBucket]
986
+ totals: dict[str, int]
977
987
  #: event_type -> duration aggregate over the whole window. Only ever keyed by
978
988
  #: ``ar_session_ended``; the key is absent when nothing in the window carried one.
979
989
  durations: dict[str, UsageDuration] = Field(default_factory=dict)
@@ -993,9 +1003,7 @@ class TagsResponse(_Base):
993
1003
 
994
1004
  class WebhookEndpoint(_Base):
995
1005
  id: str
996
- # F-1.4: an endpoint binds to an org; project_id is null on every one created without.
997
- org_id: str | None = None
998
- project_id: str | None = None
1006
+ org_id: str | None = None # an endpoint binds to its org
999
1007
  url: str
1000
1008
  description: str | None = None
1001
1009
  events: list[WebhookEventType]
@@ -1024,6 +1032,8 @@ class WebhookDelivery(_Base):
1024
1032
  succeeded_at: datetime | None = None
1025
1033
  last_attempt_at: datetime | None = None
1026
1034
  last_error: str | None = None
1035
+ # When the next retry is due; None once it succeeded or its six attempts ran out.
1036
+ next_attempt_at: datetime | None = None
1027
1037
  payload_json: dict[str, Any] | None = None
1028
1038
 
1029
1039
 
@@ -1033,19 +1043,6 @@ class WebhookDeliveryListResponse(_Base):
1033
1043
  offset: int
1034
1044
 
1035
1045
 
1036
- class Project(_Base):
1037
- id: str
1038
- org_id: str
1039
- name: str
1040
- allowed_domains: list[str] = Field(default_factory=list)
1041
- always_generate: bool = False
1042
- created_at: datetime
1043
-
1044
-
1045
- class ProjectListResponse(_Base):
1046
- data: list[Project]
1047
-
1048
-
1049
1046
  class HealthResponse(_Base):
1050
1047
  status: str = "ok"
1051
1048
  version: str | None = None
@@ -417,6 +417,32 @@ def test_products_export_answers_a_queued_export() -> None:
417
417
  assert result.to_finish == 15 and result.notify_email == "a@example.com"
418
418
 
419
419
 
420
+ def test_products_qr_returns_the_png_bytes() -> None:
421
+ client, rec = make_client(
422
+ httpx.Response(200, content=b"\x89PNG\r\n", headers={"content-type": "image/png"})
423
+ )
424
+ png = client.products.qr("p1", guide=True, size=512)
425
+
426
+ assert png == b"\x89PNG\r\n"
427
+ assert rec.request is not None
428
+ assert rec.request.url.path == "/v1/products/p1/qr"
429
+ assert rec.request.url.params["guide"] == "true"
430
+ assert rec.request.url.params["size"] == "512"
431
+
432
+
433
+ def test_products_qr_defaults_to_the_minimal_1024_square() -> None:
434
+ client, rec = make_client(httpx.Response(200, content=b"\x89PNG"))
435
+ client.products.qr("p1")
436
+
437
+ assert rec.request is not None
438
+ assert rec.request.url.params["guide"] == "false"
439
+ assert rec.request.url.params["size"] == "1024"
440
+
441
+
442
+ def test_product_carries_its_viewer_url() -> None:
443
+ assert Product.model_fields["viewer_url"].default is None
444
+
445
+
420
446
  def test_usage_group_by_product_ranks_and_names_them() -> None:
421
447
  body = {
422
448
  "start": "2026-09-01T00:00:00Z",
@@ -2,4 +2,4 @@ import viewrium
2
2
 
3
3
 
4
4
  def test_import() -> None:
5
- assert viewrium.__version__ == "2.3.0"
5
+ assert viewrium.__version__ == "2.4.0"
@@ -0,0 +1,137 @@
1
+ """Drift guard: the hand-written models in `viewrium._models` against the API's public OpenAPI
2
+ schema (`apps/api/openapi.json`, the file the JS SDK is generated from).
3
+
4
+ Every public component schema must have a Python counterpart with the same field names and the
5
+ same requiredness (an object), or the same values (an enum). Names differ where the SDK chose a
6
+ friendlier class name (`SCHEMA_TO_MODEL`); anything the SDK deliberately does differently is in
7
+ an allow-list below, each entry with its reason. A new API field fails this test until the SDK
8
+ mirrors it or the difference is allow-listed on purpose.
9
+
10
+ It runs as part of `test` and again as the package's `check` task, which CI runs on every PR
11
+ (unlike `test`, which CI runs only for affected packages).
12
+ """
13
+
14
+ from __future__ import annotations
15
+
16
+ import json
17
+ from enum import StrEnum
18
+ from pathlib import Path
19
+ from typing import Any
20
+
21
+ import pytest
22
+ from pydantic import BaseModel
23
+
24
+ import viewrium
25
+ from viewrium import _models
26
+
27
+ OPENAPI_PATH = Path(__file__).resolve().parents[3] / "apps" / "api" / "openapi.json"
28
+
29
+ # OpenAPI component name -> `viewrium._models` class name, where they differ.
30
+ SCHEMA_TO_MODEL: dict[str, str] = {
31
+ "ApiKeyResponse": "ApiKey",
32
+ "ModelPlanResponse": "ModelPlan",
33
+ "ProductExportQueuedResponse": "ProductExportQueued",
34
+ "ProductImageResponse": "ProductImage",
35
+ "ProductModelResponse": "ProductModel",
36
+ "ProductOrderParkedResponse": "ProductOrderParked",
37
+ "ProductParkedResponse": "ProductParked",
38
+ "ProductResponse": "Product",
39
+ "ProductSourceResponse": "ProductSource",
40
+ "PublicProductResponse": "PublicProduct",
41
+ "TicketResponse": "Ticket",
42
+ "WebhookDeliveryResponse": "WebhookDelivery",
43
+ "WebhookEndpointResponse": "WebhookEndpoint",
44
+ }
45
+
46
+ # Component schemas with no Python model, on purpose.
47
+ UNMODELLED: dict[str, str] = {
48
+ "ErrorEnvelope": "parsed into the ViewriumError hierarchy (_errors.py), not a model",
49
+ "ErrorDetail": "parsed into the ViewriumError hierarchy (_errors.py), not a model",
50
+ }
51
+
52
+ # (component, field) pairs whose requiredness differs on purpose.
53
+ REQUIREDNESS_EXCEPTIONS: dict[tuple[str, str], str] = {}
54
+
55
+ # (component, field) pairs present on one side only, on purpose.
56
+ FIELD_EXCEPTIONS: dict[tuple[str, str], str] = {}
57
+
58
+
59
+ def _schemas() -> dict[str, dict[str, Any]]:
60
+ document = json.loads(OPENAPI_PATH.read_text(encoding="utf-8"))
61
+ schemas: dict[str, dict[str, Any]] = document["components"]["schemas"]
62
+ return schemas
63
+
64
+
65
+ SCHEMAS = _schemas()
66
+
67
+
68
+ def _model_for(name: str) -> type[Any] | None:
69
+ found = getattr(_models, SCHEMA_TO_MODEL.get(name, name), None)
70
+ return found if isinstance(found, type) else None
71
+
72
+
73
+ @pytest.mark.parametrize("name", sorted(SCHEMAS))
74
+ def test_every_public_schema_has_a_python_counterpart(name: str) -> None:
75
+ if name in UNMODELLED:
76
+ return
77
+ model = _model_for(name)
78
+ assert model is not None, (
79
+ f"OpenAPI schema {name!r} has no model in viewrium._models "
80
+ f"(add one, map it in SCHEMA_TO_MODEL, or allow-list it in UNMODELLED with a reason)"
81
+ )
82
+ # The docs' object pages name every model as `viewrium.<Name>`.
83
+ assert getattr(viewrium, model.__name__, None) is model, (
84
+ f"{model.__name__} is not exported from the viewrium package"
85
+ )
86
+
87
+
88
+ @pytest.mark.parametrize("name", sorted(n for n, s in SCHEMAS.items() if "enum" in s))
89
+ def test_enum_values_match(name: str) -> None:
90
+ model = _model_for(name)
91
+ if model is None:
92
+ pytest.skip("reported by test_every_public_schema_has_a_python_counterpart")
93
+ assert issubclass(model, StrEnum), f"{name}: expected a StrEnum, got {model!r}"
94
+ assert {m.value for m in model} == set(SCHEMAS[name]["enum"]), f"{name}: enum values differ"
95
+
96
+
97
+ @pytest.mark.parametrize("name", sorted(n for n, s in SCHEMAS.items() if "properties" in s))
98
+ def test_object_fields_and_requiredness_match(name: str) -> None:
99
+ if name in UNMODELLED:
100
+ return
101
+ model = _model_for(name)
102
+ if model is None:
103
+ pytest.skip("reported by test_every_public_schema_has_a_python_counterpart")
104
+ assert issubclass(model, BaseModel), f"{name}: expected a pydantic model, got {model!r}"
105
+ schema = SCHEMAS[name]
106
+ api_fields = set(schema["properties"])
107
+ py_fields = set(model.model_fields)
108
+ one_sided = {f for f in api_fields ^ py_fields if (name, f) not in FIELD_EXCEPTIONS}
109
+ assert not one_sided, (
110
+ f"{name} vs {model.__name__}: only in the API {sorted(api_fields - py_fields)}, "
111
+ f"only in the SDK {sorted(py_fields - api_fields)}"
112
+ )
113
+ api_required = set(schema.get("required", []))
114
+ mismatched = sorted(
115
+ f
116
+ for f in api_fields & py_fields
117
+ if (f in api_required) != model.model_fields[f].is_required()
118
+ and (name, f) not in REQUIREDNESS_EXCEPTIONS
119
+ )
120
+ assert not mismatched, (
121
+ f"{name} vs {model.__name__}: requiredness differs for {mismatched} "
122
+ f"(API required: {sorted(api_required & set(mismatched))})"
123
+ )
124
+
125
+
126
+ def test_allow_lists_name_real_entries() -> None:
127
+ """A stale allow-list entry hides nothing and would let the next real drift through."""
128
+ for name in UNMODELLED:
129
+ assert name in SCHEMAS, f"UNMODELLED names {name!r}, which the schema no longer has"
130
+ for name in SCHEMA_TO_MODEL:
131
+ assert name in SCHEMAS, f"SCHEMA_TO_MODEL maps {name!r}, which the schema no longer has"
132
+ for name, field in REQUIREDNESS_EXCEPTIONS:
133
+ assert field in SCHEMAS.get(name, {}).get("properties", {}), (
134
+ f"REQUIREDNESS_EXCEPTIONS names {name}.{field}, which the schema no longer has"
135
+ )
136
+ for name, _field in FIELD_EXCEPTIONS:
137
+ assert name in SCHEMAS, f"FIELD_EXCEPTIONS names {name!r}, which the schema no longer has"
@@ -0,0 +1,16 @@
1
+ {
2
+ "$schema": "https://turborepo.dev/schema.json",
3
+ "extends": ["//"],
4
+ "tags": ["package"],
5
+ "tasks": {
6
+ "build": {
7
+ "outputs": []
8
+ },
9
+ "test": {
10
+ "inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/apps/api/openapi.json"]
11
+ },
12
+ "check": {
13
+ "inputs": ["$TURBO_DEFAULT$", "$TURBO_ROOT$/apps/api/openapi.json"]
14
+ }
15
+ }
16
+ }
@@ -448,7 +448,7 @@ wheels = [
448
448
 
449
449
  [[package]]
450
450
  name = "viewrium"
451
- version = "2.3.0"
451
+ version = "2.4.0"
452
452
  source = { editable = "." }
453
453
  dependencies = [
454
454
  { name = "httpx" },
viewrium-2.3.0/turbo.json DELETED
@@ -1,10 +0,0 @@
1
- {
2
- "$schema": "https://turborepo.dev/schema.json",
3
- "extends": ["//"],
4
- "tags": ["package"],
5
- "tasks": {
6
- "build": {
7
- "outputs": []
8
- }
9
- }
10
- }
File without changes
File without changes
File without changes
File without changes