stackshift 1.0.1__tar.gz → 1.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.
Files changed (46) hide show
  1. {stackshift-1.0.1 → stackshift-1.2.0}/PKG-INFO +70 -1
  2. {stackshift-1.0.1 → stackshift-1.2.0}/README.md +69 -0
  3. {stackshift-1.0.1 → stackshift-1.2.0}/pyproject.toml +1 -1
  4. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift/__init__.py +4 -0
  5. stackshift-1.2.0/stackshift/ai_credits.py +24 -0
  6. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift/assets.py +6 -0
  7. stackshift-1.2.0/stackshift/assets_dam.py +193 -0
  8. stackshift-1.2.0/stackshift/assets_media.py +48 -0
  9. stackshift-1.2.0/stackshift/assets_platform.py +99 -0
  10. stackshift-1.2.0/stackshift/assets_video.py +65 -0
  11. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift/client.py +4 -0
  12. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift/mail.py +24 -1
  13. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift/mail_advanced.py +4 -0
  14. stackshift-1.2.0/stackshift/mail_billing.py +9 -0
  15. stackshift-1.2.0/stackshift/mail_brands.py +35 -0
  16. stackshift-1.2.0/stackshift/mail_campaigns.py +108 -0
  17. stackshift-1.2.0/stackshift/mail_marketing.py +35 -0
  18. stackshift-1.2.0/stackshift/mail_migration.py +20 -0
  19. stackshift-1.2.0/stackshift/mail_tracking.py +33 -0
  20. stackshift-1.2.0/stackshift/workload_security.py +67 -0
  21. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift.egg-info/PKG-INFO +70 -1
  22. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift.egg-info/SOURCES.txt +19 -1
  23. stackshift-1.2.0/tests/test_ai_credits.py +34 -0
  24. stackshift-1.2.0/tests/test_assets_media.py +110 -0
  25. stackshift-1.2.0/tests/test_assets_platform.py +41 -0
  26. stackshift-1.2.0/tests/test_mail_platform.py +29 -0
  27. stackshift-1.2.0/tests/test_mail_simulation.py +28 -0
  28. stackshift-1.2.0/tests/test_mail_subscribers.py +37 -0
  29. stackshift-1.2.0/tests/test_mail_tracking.py +37 -0
  30. stackshift-1.0.1/stackshift/mail_campaigns.py +0 -61
  31. {stackshift-1.0.1 → stackshift-1.2.0}/setup.cfg +0 -0
  32. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift/assets_workflows.py +0 -0
  33. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift/mail_events_webhooks.py +0 -0
  34. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift/mail_exports.py +0 -0
  35. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift/mail_reputation.py +0 -0
  36. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift/mail_streams.py +0 -0
  37. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift/projects.py +0 -0
  38. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift.egg-info/dependency_links.txt +0 -0
  39. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift.egg-info/requires.txt +0 -0
  40. {stackshift-1.0.1 → stackshift-1.2.0}/stackshift.egg-info/top_level.txt +0 -0
  41. {stackshift-1.0.1 → stackshift-1.2.0}/tests/test_assets_workflows.py +0 -0
  42. {stackshift-1.0.1 → stackshift-1.2.0}/tests/test_mail.py +0 -0
  43. {stackshift-1.0.1 → stackshift-1.2.0}/tests/test_mail_advanced.py +0 -0
  44. {stackshift-1.0.1 → stackshift-1.2.0}/tests/test_mail_diagnostics.py +0 -0
  45. {stackshift-1.0.1 → stackshift-1.2.0}/tests/test_mail_events_webhooks.py +0 -0
  46. {stackshift-1.0.1 → stackshift-1.2.0}/tests/test_mail_exports.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stackshift
3
- Version: 1.0.1
3
+ Version: 1.2.0
4
4
  Summary: Official Python SDK for StackShift.
5
5
  Requires-Python: >=3.9
6
6
  Description-Content-Type: text/markdown
@@ -16,6 +16,27 @@ Official Python SDK for StackShift.
16
16
  pip install stackshift
17
17
  ```
18
18
 
19
+ ## AI credits
20
+
21
+ AI credits are account-scoped. Use the shared client to inspect usage, start a top-up, or select managed billing versus your own provider key:
22
+
23
+ ```python
24
+ from stackshift import StackShift
25
+
26
+ stackshift = StackShift()
27
+ balance = stackshift.ai_credits.balance()
28
+ usage = stackshift.ai_credits.usage(product="assets", limit=25)
29
+ quote = stackshift.ai_credits.quote(1_000, "USD")
30
+ checkout = stackshift.ai_credits.checkout(
31
+ quote["id"],
32
+ "unique-checkout-id",
33
+ "paystack",
34
+ )
35
+ stackshift.ai_credits.set_funding("assets", "managed")
36
+ ```
37
+
38
+ Keep account API keys and checkout creation on your server.
39
+
19
40
  ## Send email
20
41
 
21
42
  ```python
@@ -213,3 +234,51 @@ upload = stackshift.assets.signed_upload_url(
213
234
  Then upload the browser `File` to `upload["url"]` from your frontend. Do not expose your StackShift API key to browser code.
214
235
 
215
236
  The SDK only talks to the StackShift REST API. Storage placement, replication, disks, and repair are StackShift internals.
237
+
238
+ ### Campaign drafts and engagement
239
+
240
+ `mail.campaigns.create(content={...})` accepts a private campaign content snapshot; template/version inputs still work. Save the complete draft with `update(id, revision=revision, **draft)` (draft keys use API camelCase). `preview`, `test`, `send(id, revision=revision)`, and `schedule(id, send_at, revision=revision)` protect the reviewed content. Stale revisions return 409.
241
+
242
+ Send methods accept `tracking={"opens": False, "clicks": True}`. Omitted fields inherit workspace defaults. `mail.tracking` exposes `settings`, `update_settings`, `message`, `campaign`, and branded-domain methods. Deployment capability flags control availability. Opens are approximate; detailed activity expires after 90 days. OTPs and tests never track.
243
+
244
+ ### Isolated testing, brands, migration, and spending
245
+
246
+ Use a `sspat_test_` credential and `simulation={"scenario": "delayed"}` for a 60-second simulated delay. Delivered, bounced, and complained outcomes are also supported. Test resources are isolated; no real email is delivered.
247
+
248
+ ```python
249
+ brand = client.mail.brands.create(name="Product", editable_fields=["company"])
250
+ audience = client.mail.audiences.create(brand_id=brand["id"], name="Product news")
251
+ ```
252
+
253
+ Audience creation requires an explicit `brand_id`. Shared profile fields belong to the brand; consent stays per audience. `mail.automations`, `mail.forms`, and `mail.segments` expose create/list methods; their input dictionaries use API camelCase keys.
254
+
255
+ `mail.migration` supports public DNS audits/plans and authenticated checklists. `mail.billing.summary()` and `mail.campaigns.estimate(id)` expose allowance and credit. Pass `approved_max_kobo=0` (or another approved maximum) alongside `revision` when sending/scheduling campaigns. Billing remains inactive until a rate card is explicitly published and activated; funding and spending opt-in are separate owner-only dashboard actions.
256
+
257
+ ## Native video, governed DAM and product rendering
258
+
259
+ Use the space-scoped DAM and video clients for collaborators, metadata schemas, bucket governance, reviewed publications, picker capabilities, model preparation, product rendering, galleries, version-pinned encoding, captions and playback sessions.
260
+
261
+ ```python
262
+ dam = sdk.assets.dam.for_space(space_id)
263
+ video = sdk.assets.video.for_space(space_id)
264
+ schema = dam.create_metadata_schema({"name": "Products", "fields": [{
265
+ "key": "product_name", "label": "Product name", "type": "text", "required": True,
266
+ }]})
267
+ published = dam.publish_metadata_schema(schema["id"], schema["revision"])
268
+ workspace = video.workspace(asset_id)
269
+ ```
270
+
271
+ Mutations carry the supplied revision in `If-Match`. Model preparation and rendering carry an idempotency key; render submission also carries the accepted maximum units. Playback renewal and events authenticate with the session credential, not the account key. Keep these clients on your backend and return grants with `Cache-Control: private, no-store`.
272
+
273
+ See the [Assets SDK guide](https://docs.stackshift.cloud/assets/sdk-media-workflows) and its linked feature guides for complete language examples, inputs, permissions, review transitions and browser callbacks.
274
+
275
+ ## Assets storage and Cloudinary migration
276
+
277
+ `sdk.assets.platform.for_space(space_id)` exposes `connections`, `storage`, and `migrations`. Use a verified Cloudinary connection, run a dry migration first, inspect its report, then start the transfer with the same folder prefix and conflict policy.
278
+
279
+ ```python
280
+ platform = sdk.assets.platform.for_space(space_id)
281
+ preview = platform.migrations.start({"source_connection_id": connection_id,
282
+ "destination_bucket_id": bucket_id, "source_prefix": "campaigns/2026", "dry_run": True})
283
+ report = platform.migrations.report(preview["id"])
284
+ ```
@@ -8,6 +8,27 @@ Official Python SDK for StackShift.
8
8
  pip install stackshift
9
9
  ```
10
10
 
11
+ ## AI credits
12
+
13
+ AI credits are account-scoped. Use the shared client to inspect usage, start a top-up, or select managed billing versus your own provider key:
14
+
15
+ ```python
16
+ from stackshift import StackShift
17
+
18
+ stackshift = StackShift()
19
+ balance = stackshift.ai_credits.balance()
20
+ usage = stackshift.ai_credits.usage(product="assets", limit=25)
21
+ quote = stackshift.ai_credits.quote(1_000, "USD")
22
+ checkout = stackshift.ai_credits.checkout(
23
+ quote["id"],
24
+ "unique-checkout-id",
25
+ "paystack",
26
+ )
27
+ stackshift.ai_credits.set_funding("assets", "managed")
28
+ ```
29
+
30
+ Keep account API keys and checkout creation on your server.
31
+
11
32
  ## Send email
12
33
 
13
34
  ```python
@@ -205,3 +226,51 @@ upload = stackshift.assets.signed_upload_url(
205
226
  Then upload the browser `File` to `upload["url"]` from your frontend. Do not expose your StackShift API key to browser code.
206
227
 
207
228
  The SDK only talks to the StackShift REST API. Storage placement, replication, disks, and repair are StackShift internals.
229
+
230
+ ### Campaign drafts and engagement
231
+
232
+ `mail.campaigns.create(content={...})` accepts a private campaign content snapshot; template/version inputs still work. Save the complete draft with `update(id, revision=revision, **draft)` (draft keys use API camelCase). `preview`, `test`, `send(id, revision=revision)`, and `schedule(id, send_at, revision=revision)` protect the reviewed content. Stale revisions return 409.
233
+
234
+ Send methods accept `tracking={"opens": False, "clicks": True}`. Omitted fields inherit workspace defaults. `mail.tracking` exposes `settings`, `update_settings`, `message`, `campaign`, and branded-domain methods. Deployment capability flags control availability. Opens are approximate; detailed activity expires after 90 days. OTPs and tests never track.
235
+
236
+ ### Isolated testing, brands, migration, and spending
237
+
238
+ Use a `sspat_test_` credential and `simulation={"scenario": "delayed"}` for a 60-second simulated delay. Delivered, bounced, and complained outcomes are also supported. Test resources are isolated; no real email is delivered.
239
+
240
+ ```python
241
+ brand = client.mail.brands.create(name="Product", editable_fields=["company"])
242
+ audience = client.mail.audiences.create(brand_id=brand["id"], name="Product news")
243
+ ```
244
+
245
+ Audience creation requires an explicit `brand_id`. Shared profile fields belong to the brand; consent stays per audience. `mail.automations`, `mail.forms`, and `mail.segments` expose create/list methods; their input dictionaries use API camelCase keys.
246
+
247
+ `mail.migration` supports public DNS audits/plans and authenticated checklists. `mail.billing.summary()` and `mail.campaigns.estimate(id)` expose allowance and credit. Pass `approved_max_kobo=0` (or another approved maximum) alongside `revision` when sending/scheduling campaigns. Billing remains inactive until a rate card is explicitly published and activated; funding and spending opt-in are separate owner-only dashboard actions.
248
+
249
+ ## Native video, governed DAM and product rendering
250
+
251
+ Use the space-scoped DAM and video clients for collaborators, metadata schemas, bucket governance, reviewed publications, picker capabilities, model preparation, product rendering, galleries, version-pinned encoding, captions and playback sessions.
252
+
253
+ ```python
254
+ dam = sdk.assets.dam.for_space(space_id)
255
+ video = sdk.assets.video.for_space(space_id)
256
+ schema = dam.create_metadata_schema({"name": "Products", "fields": [{
257
+ "key": "product_name", "label": "Product name", "type": "text", "required": True,
258
+ }]})
259
+ published = dam.publish_metadata_schema(schema["id"], schema["revision"])
260
+ workspace = video.workspace(asset_id)
261
+ ```
262
+
263
+ Mutations carry the supplied revision in `If-Match`. Model preparation and rendering carry an idempotency key; render submission also carries the accepted maximum units. Playback renewal and events authenticate with the session credential, not the account key. Keep these clients on your backend and return grants with `Cache-Control: private, no-store`.
264
+
265
+ See the [Assets SDK guide](https://docs.stackshift.cloud/assets/sdk-media-workflows) and its linked feature guides for complete language examples, inputs, permissions, review transitions and browser callbacks.
266
+
267
+ ## Assets storage and Cloudinary migration
268
+
269
+ `sdk.assets.platform.for_space(space_id)` exposes `connections`, `storage`, and `migrations`. Use a verified Cloudinary connection, run a dry migration first, inspect its report, then start the transfer with the same folder prefix and conflict policy.
270
+
271
+ ```python
272
+ platform = sdk.assets.platform.for_space(space_id)
273
+ preview = platform.migrations.start({"source_connection_id": connection_id,
274
+ "destination_bucket_id": bucket_id, "source_prefix": "campaigns/2026", "dry_run": True})
275
+ report = platform.migrations.report(preview["id"])
276
+ ```
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "stackshift"
7
- version = "1.0.1"
7
+ version = "1.2.0"
8
8
  description = "Official Python SDK for StackShift."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -1,4 +1,5 @@
1
1
  from .client import StackShift
2
+ from .ai_credits import AICreditsClient
2
3
  from .assets import ASSET_TRANSFORM_PRESETS, AssetsClient, asset_transform_options, asset_transform_spec, get_asset_transform_preset
3
4
  from .mail import (
4
5
  MailClient,
@@ -13,9 +14,11 @@ from .mail_streams import MailStreamsClient
13
14
  from .mail_campaigns import MailAudiencesClient, MailCampaignsClient
14
15
  from .mail_exports import MailExportsClient
15
16
  from .projects import ProjectsClient
17
+ from .workload_security import WorkloadSecurityClient
16
18
 
17
19
  __all__ = [
18
20
  "StackShift",
21
+ "AICreditsClient",
19
22
  "ASSET_TRANSFORM_PRESETS",
20
23
  "AssetsClient",
21
24
  "MailClient",
@@ -33,6 +36,7 @@ __all__ = [
33
36
  "MailCampaignsClient",
34
37
  "MailExportsClient",
35
38
  "ProjectsClient",
39
+ "WorkloadSecurityClient",
36
40
  "asset_transform_options",
37
41
  "asset_transform_spec",
38
42
  "get_asset_transform_preset",
@@ -0,0 +1,24 @@
1
+ from typing import Any
2
+
3
+
4
+ class AICreditsClient:
5
+ def __init__(self, client: Any) -> None:
6
+ self._client = client
7
+
8
+ def balance(self) -> dict[str, Any]:
9
+ return self._client.request("GET", "/billing/ai-credits")
10
+
11
+ def usage(self, **filters: Any) -> dict[str, Any]:
12
+ return self._client.request("GET", "/billing/ai-credits/usage", params=filters)
13
+
14
+ def quote(self, credits: int, currency: str) -> dict[str, Any]:
15
+ return self._client.request("POST", "/billing/ai-credits/top-ups/quote", json={"credits": credits, "currency": currency})
16
+
17
+ def checkout(self, quote_id: str, idempotency_key: str, provider: str) -> dict[str, Any]:
18
+ return self._client.request("POST", "/billing/ai-credits/top-ups/checkout", json={"quote_id": quote_id, "idempotency_key": idempotency_key, "provider": provider})
19
+
20
+ def funding(self) -> dict[str, str]:
21
+ return self._client.request("GET", "/billing/ai-credits/funding")
22
+
23
+ def set_funding(self, product: str, mode: str) -> dict[str, str]:
24
+ return self._client.request("PUT", "/billing/ai-credits/funding", json={"product": product, "mode": mode})
@@ -7,6 +7,9 @@ from typing import Any, BinaryIO
7
7
  from urllib.parse import quote
8
8
 
9
9
  from .assets_workflows import AssetWorkflowsMixin
10
+ from .assets_dam import AssetDAMClient
11
+ from .assets_video import AssetVideoClient
12
+ from .assets_platform import AssetPlatformClient
10
13
 
11
14
 
12
15
  ASSET_TRANSFORM_PRESETS: list[dict[str, Any]] = [
@@ -52,6 +55,9 @@ def asset_transform_spec(**options: Any) -> str:
52
55
  class AssetsClient(AssetWorkflowsMixin):
53
56
  def __init__(self, client: Any) -> None:
54
57
  self._client = client
58
+ self.dam = AssetDAMClient(client)
59
+ self.video = AssetVideoClient(client)
60
+ self.platform = AssetPlatformClient(client)
55
61
 
56
62
  def upload(
57
63
  self,
@@ -0,0 +1,193 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+ from urllib.parse import quote
5
+
6
+ from .assets_media import AssetMediaClient
7
+
8
+
9
+ class AssetDAMClient(AssetMediaClient):
10
+ def spaces(self):
11
+ return self._request("GET", f"/assets/spaces")
12
+
13
+ def collaborators(self):
14
+ return self._request("GET", f"/assets/collaborators")
15
+
16
+ def invite(self, input: dict[str, Any]):
17
+ return self._request("POST", f"/assets/collaborators", body=input)
18
+
19
+ def accept_invitation(self, id: str):
20
+ return self._request("POST", f"/assets/invitations/{quote(id, safe='')}/accept")
21
+
22
+ def update_collaborator(self, id: str, revision: int, actions: list[str]):
23
+ return self._request(
24
+ "PUT",
25
+ f"/assets/collaborators/{quote(id, safe='')}",
26
+ body={"actions": actions},
27
+ revision=revision,
28
+ )
29
+
30
+ def revoke_collaborator(self, id: str, revision: int):
31
+ return self._request(
32
+ "DELETE", f"/assets/collaborators/{quote(id, safe='')}", revision=revision
33
+ )
34
+
35
+ def metadata_schemas(self):
36
+ return self._request("GET", f"/assets/metadata-schemas")
37
+
38
+ def metadata_editor(self, asset_id: str):
39
+ return self._request(
40
+ "GET", f"/assets/{quote(asset_id, safe='')}/metadata-editor"
41
+ )
42
+
43
+ def create_metadata_schema(self, input: dict[str, Any]):
44
+ return self._request("POST", f"/assets/metadata-schemas", body=input)
45
+
46
+ def update_metadata_schema(self, id: str, revision: int, input: dict[str, Any]):
47
+ return self._request(
48
+ "PUT",
49
+ f"/assets/metadata-schemas/{quote(id, safe='')}",
50
+ body=input,
51
+ revision=revision,
52
+ )
53
+
54
+ def publish_metadata_schema(self, id: str, revision: int):
55
+ return self._request(
56
+ "POST",
57
+ f"/assets/metadata-schemas/{quote(id, safe='')}/publish",
58
+ revision=revision,
59
+ )
60
+
61
+ def bucket_governance(self, id: str):
62
+ return self._request("GET", f"/assets/buckets/{quote(id, safe='')}/governance")
63
+
64
+ def save_bucket_governance(self, id: str, input: dict[str, Any]):
65
+ return self._request(
66
+ "PUT", f"/assets/buckets/{quote(id, safe='')}/governance", body=input
67
+ )
68
+
69
+ def migrate_bucket_governance(self, id: str, revision: int):
70
+ return self._request(
71
+ "POST",
72
+ f"/assets/buckets/{quote(id, safe='')}/governance/migrate",
73
+ revision=revision,
74
+ )
75
+
76
+ def publications(self, query: dict[str, Any] | None = None):
77
+ return self._request("GET", f"/assets/publications", query=query)
78
+
79
+ def publication_renditions(self, asset_id: str):
80
+ return self._request(
81
+ "GET", f"/assets/{quote(asset_id, safe='')}/publication-renditions"
82
+ )
83
+
84
+ def create_publication(self, input: dict[str, Any]):
85
+ return self._request("POST", f"/assets/publications", body=input)
86
+
87
+ def update_publication(self, id: str, revision: int, input: dict[str, Any]):
88
+ return self._request(
89
+ "PUT",
90
+ f"/assets/publications/{quote(id, safe='')}",
91
+ body=input,
92
+ revision=revision,
93
+ )
94
+
95
+ def transition_publication(self, id: str, revision: int, action: str, note: str):
96
+ return self._request(
97
+ "POST",
98
+ f"/assets/publications/{quote(id, safe='')}/{quote(action, safe='')}",
99
+ body={"note": note},
100
+ revision=revision,
101
+ )
102
+
103
+ def resolve_publication(self, id: str):
104
+ return self._request(
105
+ "GET", f"/assets/publications/{quote(id, safe='')}/resolve"
106
+ )
107
+
108
+ def preview_publication(self, id: str):
109
+ return self._request(
110
+ "GET", f"/assets/publications/{quote(id, safe='')}/preview"
111
+ )
112
+
113
+ def resolve_publication_ar(self, id: str):
114
+ return self._request("POST", f"/assets/publications/{quote(id, safe='')}/ar")
115
+
116
+ def create_picker_capability(self, input: dict[str, Any]):
117
+ return self._request("POST", f"/assets/picker-capabilities", body=input)
118
+
119
+ def revoke_picker_capability(self, id: str):
120
+ return self._request(
121
+ "DELETE", f"/assets/picker-capabilities/{quote(id, safe='')}"
122
+ )
123
+
124
+ def models(self, asset_id: str):
125
+ return self._request("GET", f"/assets/{quote(asset_id, safe='')}/models")
126
+
127
+ def estimate_render(self, asset_id: str, revision: int, input: dict[str, Any]):
128
+ return self._request(
129
+ "POST",
130
+ f"/assets/{quote(asset_id, safe='')}/models",
131
+ body={**input, "operation": "estimate"},
132
+ revision=revision,
133
+ )
134
+
135
+ def render_product(
136
+ self,
137
+ asset_id: str,
138
+ revision: int,
139
+ idempotency_key: str,
140
+ input: dict[str, Any],
141
+ maximum_units: int,
142
+ ):
143
+ return self._request(
144
+ "POST",
145
+ f"/assets/{quote(asset_id, safe='')}/models",
146
+ body={**input, "operation": "render", "maximum_units": maximum_units},
147
+ revision=revision,
148
+ idempotency_key=idempotency_key,
149
+ )
150
+
151
+ def process_model(self, asset_id: str, revision: int, idempotency_key: str):
152
+ return self._request(
153
+ "POST",
154
+ f"/assets/{quote(asset_id, safe='')}/models",
155
+ revision=revision,
156
+ idempotency_key=idempotency_key,
157
+ )
158
+
159
+ def galleries(self, query: dict[str, Any] | None = None):
160
+ return self._request("GET", f"/assets/galleries", query=query)
161
+
162
+ def create_gallery(self, input: dict[str, Any]):
163
+ return self._request("POST", f"/assets/galleries", body=input)
164
+
165
+ def update_gallery(self, id: str, revision: int, input: dict[str, Any]):
166
+ return self._request(
167
+ "PUT",
168
+ f"/assets/galleries/{quote(id, safe='')}",
169
+ body=input,
170
+ revision=revision,
171
+ )
172
+
173
+ def transition_gallery(self, id: str, revision: int, action: str):
174
+ return self._request(
175
+ "POST",
176
+ f"/assets/galleries/{quote(id, safe='')}/{quote(action, safe='')}",
177
+ revision=revision,
178
+ )
179
+
180
+ def resolve_gallery(self, id: str):
181
+ return self._request("GET", f"/assets/galleries/{quote(id, safe='')}/resolve")
182
+
183
+ def preview_gallery(self, id: str):
184
+ return self._request(
185
+ "GET", f"/assets/galleries/{quote(id, safe='')}/resolve?preview=true"
186
+ )
187
+
188
+ def resolve_gallery_ar(self, id: str, publication_id: str):
189
+ return self._request(
190
+ "POST",
191
+ f"/assets/galleries/{quote(id, safe='')}/ar",
192
+ body={"publication_id": publication_id},
193
+ )
@@ -0,0 +1,48 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+ from urllib.parse import urlsplit
5
+
6
+
7
+ class AssetMediaClient:
8
+ def __init__(self, client: Any, space_id: str = "") -> None:
9
+ self._client = client
10
+ self._space_id = space_id
11
+
12
+ def for_space(self, space_id: str):
13
+ return type(self)(self._client, space_id)
14
+
15
+ def _request(
16
+ self,
17
+ method: str,
18
+ path: str,
19
+ *,
20
+ body=None,
21
+ revision=None,
22
+ idempotency_key=None,
23
+ query=None,
24
+ ):
25
+ headers = {}
26
+ if self._space_id:
27
+ headers["X-Asset-Space-ID"] = self._space_id
28
+ if revision is not None:
29
+ headers["If-Match"] = f'"{revision}"'
30
+ if idempotency_key is not None:
31
+ headers["Idempotency-Key"] = idempotency_key
32
+ return self._client.request(
33
+ method, path, json=body, headers=headers, params=query
34
+ )
35
+
36
+ def _playback(self, path: str, credential: str, body: dict[str, Any]):
37
+ from .client import StackShift
38
+
39
+ if not credential.strip():
40
+ raise ValueError("Playback credential is required")
41
+ base = urlsplit(self._client.base_url)
42
+ # A separate client prevents account authentication from replacing the session credential.
43
+ playback = StackShift(
44
+ api_key=credential,
45
+ base_url=f"{base.scheme}://{base.netloc}",
46
+ session=self._client.session,
47
+ )
48
+ return playback.request("POST", "/playback" + path, json=body)
@@ -0,0 +1,99 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+ from urllib.parse import quote
5
+
6
+
7
+ def _id(value: str) -> str:
8
+ return quote(value, safe="")
9
+
10
+
11
+ class _ScopedTransport:
12
+ def __init__(self, client: Any, space_id: str) -> None:
13
+ self._client = client
14
+ self._space_id = space_id
15
+
16
+ def request(self, method: str, path: str, **kwargs: Any) -> dict[str, Any]:
17
+ headers = dict(kwargs.pop("headers", None) or {})
18
+ if self._space_id:
19
+ headers["X-Asset-Space-ID"] = self._space_id
20
+ return self._client.request(method, path, headers=headers, **kwargs)
21
+
22
+
23
+ class AssetConnectionsClient:
24
+ def __init__(self, client: Any) -> None:
25
+ self._client = client
26
+
27
+ def list(self) -> dict[str, Any]:
28
+ return self._client.request("GET", "/assets/connections")
29
+
30
+ def get(self, connection_id: str) -> dict[str, Any]:
31
+ return self._client.request("GET", f"/assets/connections/{_id(connection_id)}")
32
+
33
+ def create(self, input: dict[str, Any]) -> dict[str, Any]:
34
+ return self._client.request("POST", "/assets/connections", json=input)
35
+
36
+ def update(self, connection_id: str, input: dict[str, Any]) -> dict[str, Any]:
37
+ return self._client.request("PATCH", f"/assets/connections/{_id(connection_id)}", json=input)
38
+
39
+ def verify(self, connection_id: str) -> dict[str, Any]:
40
+ return self._client.request("POST", f"/assets/connections/{_id(connection_id)}/verify")
41
+
42
+ def delete(self, connection_id: str) -> dict[str, Any]:
43
+ return self._client.request("DELETE", f"/assets/connections/{_id(connection_id)}")
44
+
45
+
46
+ class AssetStorageClient:
47
+ def __init__(self, client: Any) -> None:
48
+ self._client = client
49
+
50
+ def configure(self, bucket_id: str, revision: int, input: dict[str, Any]) -> dict[str, Any]:
51
+ return self._client.request("PUT", f"/assets/buckets/{_id(bucket_id)}/storage",
52
+ json=input, headers={"If-Match": f'"{revision}"'})
53
+
54
+ def list_s2_buckets(self) -> dict[str, Any]:
55
+ return self._client.request("GET", "/assets/s2-buckets")
56
+
57
+ def create_s2_bucket(self, input: dict[str, Any]) -> dict[str, Any]:
58
+ return self._client.request("POST", "/assets/s2-buckets", json=input)
59
+
60
+ def relocate(self, bucket_id: str, input: dict[str, Any] | None = None) -> dict[str, Any]:
61
+ return self._client.request("POST", f"/assets/buckets/{_id(bucket_id)}/relocations",
62
+ json=input or {})
63
+
64
+
65
+ class AssetMigrationsClient:
66
+ def __init__(self, client: Any) -> None:
67
+ self._client = client
68
+
69
+ def start(self, input: dict[str, Any]) -> dict[str, Any]:
70
+ return self._client.request("POST", "/assets/migrations", json=input)
71
+
72
+ def list(self, limit: int | None = None) -> dict[str, Any]:
73
+ return self._client.request("GET", "/assets/migrations",
74
+ params={"limit": limit} if limit is not None else None)
75
+
76
+ def get(self, migration_id: str) -> dict[str, Any]:
77
+ return self._client.request("GET", f"/assets/migrations/{_id(migration_id)}")
78
+
79
+ def cancel(self, migration_id: str) -> dict[str, Any]:
80
+ return self._client.request("POST", f"/assets/migrations/{_id(migration_id)}/cancel")
81
+
82
+ def retry_item(self, migration_id: str, item_id: str) -> dict[str, Any]:
83
+ return self._client.request("POST", f"/assets/migrations/{_id(migration_id)}/items/{_id(item_id)}/retry")
84
+
85
+ def report(self, migration_id: str) -> dict[str, Any]:
86
+ return self._client.request("GET", f"/assets/migrations/{_id(migration_id)}/report",
87
+ params={"format": "json"})
88
+
89
+
90
+ class AssetPlatformClient:
91
+ def __init__(self, client: Any, space_id: str = "") -> None:
92
+ self._client = client
93
+ transport = _ScopedTransport(client, space_id)
94
+ self.connections = AssetConnectionsClient(transport)
95
+ self.storage = AssetStorageClient(transport)
96
+ self.migrations = AssetMigrationsClient(transport)
97
+
98
+ def for_space(self, space_id: str) -> AssetPlatformClient:
99
+ return type(self)(self._client, space_id)
@@ -0,0 +1,65 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any
4
+ from urllib.parse import quote
5
+
6
+ from .assets_media import AssetMediaClient
7
+
8
+
9
+ class AssetVideoClient(AssetMediaClient):
10
+ def workspace(self, asset_id: str):
11
+ return self._request("GET", f"/assets/{quote(asset_id, safe='')}/video")
12
+
13
+ def process(self, asset_id: str, version_id: str):
14
+ return self._request(
15
+ "POST",
16
+ f"/assets/{quote(asset_id, safe='')}/versions/{quote(version_id, safe='')}/video",
17
+ )
18
+
19
+ def create_session(self, asset_id: str):
20
+ return self._request(
21
+ "POST", f"/assets/{quote(asset_id, safe='')}/playback-sessions"
22
+ )
23
+
24
+ def revoke_session(self, asset_id: str, session_id: str):
25
+ return self._request(
26
+ "DELETE",
27
+ f"/assets/{quote(asset_id, safe='')}/playback-sessions/{quote(session_id, safe='')}",
28
+ )
29
+
30
+ def captions(self, asset_id: str, version_id: str):
31
+ return self._request(
32
+ "GET",
33
+ f"/assets/{quote(asset_id, safe='')}/versions/{quote(version_id, safe='')}/video/captions",
34
+ )
35
+
36
+ def add_caption(self, asset_id: str, version_id: str, input: dict[str, Any]):
37
+ return self._request(
38
+ "POST",
39
+ f"/assets/{quote(asset_id, safe='')}/versions/{quote(version_id, safe='')}/video/captions",
40
+ body=input,
41
+ )
42
+
43
+ def remove_caption(self, asset_id: str, version_id: str, caption_id: str):
44
+ return self._request(
45
+ "DELETE",
46
+ f"/assets/{quote(asset_id, safe='')}/versions/{quote(version_id, safe='')}/video/captions/{quote(caption_id, safe='')}",
47
+ )
48
+
49
+ def review(self, asset_id: str, version_id: str, decision: str, reason: str):
50
+ return self._request(
51
+ "POST",
52
+ f"/assets/{quote(asset_id, safe='')}/versions/{quote(version_id, safe='')}/video/review",
53
+ body={"decision": decision, "reason": reason},
54
+ )
55
+
56
+ def analytics(self, asset_id: str):
57
+ return self._request(
58
+ "GET", f"/assets/{quote(asset_id, safe='')}/video/analytics"
59
+ )
60
+
61
+ def renew_session(self, credential: str):
62
+ return self._playback("/sessions/renew", credential, {})
63
+
64
+ def events(self, credential: str, events: list[dict[str, Any]]):
65
+ return self._playback("/events", credential, {"events": events})
@@ -26,13 +26,17 @@ class StackShift:
26
26
  self.cdn_base_url = cdn_base_url.rstrip("/")
27
27
  self.session = session or requests.Session()
28
28
 
29
+ from .ai_credits import AICreditsClient
29
30
  from .assets import AssetsClient
30
31
  from .mail import MailClient
31
32
  from .projects import ProjectsClient
33
+ from .workload_security import WorkloadSecurityClient
32
34
 
35
+ self.ai_credits = AICreditsClient(self)
33
36
  self.projects = ProjectsClient(self)
34
37
  self.assets = AssetsClient(self)
35
38
  self.mail = MailClient(self)
39
+ self.workload_security = WorkloadSecurityClient(self)
36
40
 
37
41
  def request(self, method: str, path: str, **kwargs: Any) -> Any:
38
42
  return self._request(self.base_url, method, path, **kwargs)