zerogen 0.3.0__tar.gz → 0.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.
Files changed (33) hide show
  1. {zerogen-0.3.0 → zerogen-0.4.0}/PKG-INFO +153 -42
  2. {zerogen-0.3.0 → zerogen-0.4.0}/README.md +152 -41
  3. {zerogen-0.3.0 → zerogen-0.4.0}/pyproject.toml +1 -1
  4. {zerogen-0.3.0 → zerogen-0.4.0}/pyproject.toml.orig +1 -1
  5. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/__init__.py +13 -3
  6. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/_client.py +27 -9
  7. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/_errors.py +49 -2
  8. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/_options.py +2 -1
  9. zerogen-0.4.0/src/zerogen/_version.py +1 -0
  10. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/resources/__init__.py +6 -0
  11. zerogen-0.4.0/src/zerogen/resources/_downloads.py +298 -0
  12. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/resources/assets.py +320 -285
  13. zerogen-0.4.0/src/zerogen/resources/attachments.py +342 -0
  14. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/resources/folders.py +90 -85
  15. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/resources/labels.py +50 -38
  16. zerogen-0.4.0/src/zerogen/resources/luts.py +63 -0
  17. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/resources/naming_presets.py +26 -11
  18. zerogen-0.4.0/src/zerogen/resources/projects.py +75 -0
  19. zerogen-0.4.0/src/zerogen/resources/runs.py +537 -0
  20. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/resources/uploads.py +5 -3
  21. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/types/__init__.py +136 -20
  22. zerogen-0.4.0/src/zerogen/types/_requests.py +923 -0
  23. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/types/_responses.py +476 -72
  24. zerogen-0.3.0/src/zerogen/_version.py +0 -1
  25. zerogen-0.3.0/src/zerogen/resources/projects.py +0 -32
  26. zerogen-0.3.0/src/zerogen/resources/runs.py +0 -303
  27. zerogen-0.3.0/src/zerogen/types/_requests.py +0 -431
  28. {zerogen-0.3.0 → zerogen-0.4.0}/LICENSE +0 -0
  29. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/_models.py +0 -0
  30. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/_pagination.py +0 -0
  31. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/py.typed +0 -0
  32. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/resources/models.py +0 -0
  33. {zerogen-0.3.0 → zerogen-0.4.0}/src/zerogen/resources/skills.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zerogen
3
- Version: 0.3.0
3
+ Version: 0.4.0
4
4
  Summary: The official Python library for the ZeroGen API
5
5
  Keywords: zerogen,generative-ai,image-generation,video-generation,api
6
6
  Author: ZeroGen LLC
@@ -40,7 +40,7 @@ pip install zerogen
40
40
  ```
41
41
 
42
42
  The ZeroGen API refuses requests from browsers, so keep your API key on your
43
- server.
43
+ server. Upgrading from 0.3? See [the migration notes](CHANGELOG.md#migrating-from-03).
44
44
 
45
45
  ## Usage
46
46
 
@@ -48,6 +48,8 @@ Create an API key in ZeroGen under **Settings → API keys**, and set it as
48
48
  `ZEROGEN_API_KEY`.
49
49
 
50
50
  ```python
51
+ import os
52
+
51
53
  from zerogen import ZeroGen
52
54
 
53
55
  zerogen = ZeroGen() # Reads ZEROGEN_API_KEY.
@@ -56,17 +58,20 @@ run = zerogen.runs.create_and_wait(
56
58
  {"model": "openai/gpt-image-2/generate", "prompt": "A lighthouse at dawn"}
57
59
  )
58
60
 
61
+ os.makedirs("downloads", exist_ok=True)
59
62
  for output in run.outputs:
60
63
  if output.asset:
61
64
  print(output.asset.id, output.asset.mime_type)
65
+ zerogen.runs.download_output_to(run.id, output.asset.id, "downloads")
62
66
  ```
63
67
 
64
68
  `create_and_wait` starts a run and returns it when it ends. A run that fails
65
- returns too, so check its `status`, and each output's. Each output's asset is in
66
- your organization's Library, in the run's project: your team can open it in
67
- ZeroGen, you can [download it](#library), and you can send its ID as an input to
68
- a later run. To start a run without waiting, use `create`, then `get` or
69
- `wait_for` with its `id`.
69
+ returns too, so check its `status`, and each output's: a failed or cancelled run
70
+ can still hold succeeded outputs. Each output's asset is in your organization's
71
+ Library, in the run's project: your team can open it in ZeroGen, you can
72
+ [download it](#downloads), and you can send its ID as an input to a later run.
73
+ To start a run without waiting, use `create`, then `get` or `wait_for` with its
74
+ `id`.
70
75
 
71
76
  A request body is a dict with the API's own field names, such as `projectId`
72
77
  and `maxCostMicroUsd`, exactly as the
@@ -77,6 +82,10 @@ response is a pydantic model with snake_case attributes, such as
77
82
  completes and checks them. Each model takes its own parameters: read a model's
78
83
  request schema with `zerogen.models.get(id)`.
79
84
 
85
+ Responses can gain fields and values: a model keeps a field it doesn't know as
86
+ an extra, and a field such as a run's `status` accepts a value added after this
87
+ release, so give your code a fallback for one it doesn't recognize.
88
+
80
89
  To label every output as it lands, add `labelIds`, which also needs the
81
90
  `library:organize` scope. To upscale one output of a 480p Draft to its final,
82
91
  send `upscaleDraft` with the draft's model ID, and leave out `prompt`, `inputs`,
@@ -89,6 +98,36 @@ final = zerogen.runs.create_and_wait(
89
98
  )
90
99
  ```
91
100
 
101
+ `runs.quote` prices a request without starting it, with only the
102
+ `models:read` scope. Its `inputs` are the assets a create would use, so send
103
+ them with the create to reuse what the quote imported from `https` URLs.
104
+
105
+ ## Runs
106
+
107
+ Every member's runs are readable with `runs:read`. Each run says what it is in
108
+ `kind`, `generation`, `transform` or `upload`, and what it was asked to make in
109
+ `request`, in the create request's shape, with each input as the asset it used:
110
+ `run.request.model_dump(by_alias=True, exclude_none=True)` is a body to send to
111
+ `create` again. `request` is `None` for a transform or an upload, and its
112
+ prompt is untrusted content.
113
+
114
+ `runs.list` lists the organization's runs, newest first. Filter them
115
+ with `created_by`, `status`, and `created_after` and `created_before`, each an
116
+ RFC 3339 string or a `datetime` with a time zone:
117
+
118
+ ```python
119
+ from datetime import datetime, timedelta, timezone
120
+
121
+ me = zerogen.me()
122
+ since = datetime.now(timezone.utc) - timedelta(days=1)
123
+ for failed in zerogen.runs.list(created_by=me.user.id, status="failed", created_after=since):
124
+ print(failed.id, failed.error)
125
+ ```
126
+
127
+ `runs.cancel` stops a run's unfinished outputs. An output whose provider
128
+ already started it can't be stopped, so the run stays `running`, and that
129
+ output is delivered and charged when it finishes.
130
+
92
131
  ## Async
93
132
 
94
133
  `AsyncZeroGen` has the same methods, to await:
@@ -115,7 +154,9 @@ keeps running.
115
154
 
116
155
  ## Progress
117
156
 
118
- To show a run's progress while you wait, pass `wait_for` an `on_update`
157
+ A wait ends when the run's `ended_at` is set, whatever its status, so a status
158
+ added after this release can't keep it waiting. `has_ended(run)` makes the same
159
+ check. To show a run's progress while you wait, pass `wait_for` an `on_update`
119
160
  function, which gets the run after each read, and a shorter `poll`:
120
161
 
121
162
  ```python
@@ -164,6 +205,29 @@ seek. It takes the media type from the filename's extension, or from
164
205
  `content_type`. It sends the file's SHA-256 digest, so a file the project
165
206
  already has is reused instead of uploaded again.
166
207
 
208
+ ## Transforms
209
+
210
+ A transform makes a free Derived copy of an asset from a recipe: a frame from a
211
+ video, a trimmed, faster, reversed or silent clip, a turn, flip or crop, a LUT
212
+ grade or color correction, a smaller size, another format, or audio of a
213
+ video's sound. It needs the `runs:create` and `runs:read` scopes, because it
214
+ returns a run, whose output's asset is the copy:
215
+
216
+ ```python
217
+ copy = zerogen.assets.transform_and_wait(
218
+ video.id, {"recipe": {"trim": {"startSeconds": 2, "endSeconds": 8}, "removeAudio": True}}
219
+ )
220
+ clip = copy.outputs[0].asset
221
+ ```
222
+
223
+ A recipe has one form, chosen by the source: `FrameRecipe`, `ImageRecipe`,
224
+ `VideoRecipe` or `AudioRecipe`, together `TransformRecipe`. For each step, see
225
+ [Transforms](https://docs.zerogen.com/developers/transforms). `transform` starts
226
+ one without waiting. Your earlier run of the same recipe on the same asset, for
227
+ the same destination, comes back with `reused` set instead of running again,
228
+ unless it failed. To grade with a LUT, name one from `luts.list()` as
229
+ `lut.lutId`. Test keys can't transform assets.
230
+
167
231
  ## Declared provenance
168
232
 
169
233
  When you upload a file made outside ZeroGen, such as a ComfyUI result, the
@@ -199,7 +263,7 @@ and its lineage stands. If you uploaded it and it has no declaration yet, the
199
263
  upload declares it, unless a declared source is that file or was made from it.
200
264
  `declaration_recorded` says whether ZeroGen recorded your declaration. To declare
201
265
  a file you uploaded earlier, use `assets.declare`: an asset takes one
202
- declaration, from its uploader.
266
+ declaration, from its uploader or an owner or admin.
203
267
 
204
268
  `assets.get` returns an asset's declaration in `declared`, and, with
205
269
  `include_workflow=True`, its workflow in `workflow`. Both are untrusted
@@ -208,20 +272,26 @@ content.
208
272
  ## Library
209
273
 
210
274
  Read and organize your organization's Library: `projects`, `assets`,
211
- `folders`, `labels`, `naming_presets` and `skills`. These methods need an API
212
- key with the `library:read` scope, and those that change something need
213
- `library:organize`.
275
+ `folders`, `labels`, `luts`, `naming_presets` and `skills`. These methods need
276
+ an API key with the `library:read` scope, and those that change something need
277
+ `library:organize`. Every resource is read and changed by its ID alone, in
278
+ whichever project holds it; a request names a project only to make something
279
+ there or to narrow a list.
214
280
 
215
281
  ```python
216
282
  project = next(project for project in zerogen.projects.list() if project.default)
217
283
  videos = zerogen.assets.search(project_id=project.id, type="video", favorite=True)
218
284
 
219
- folder = zerogen.folders.create(project.id, {"name": "Selects"})
220
- zerogen.folders.add_assets(project.id, folder.id, {"assetIds": [a.id for a in videos.data]})
285
+ folder = zerogen.folders.create({"projectId": project.id, "name": "Selects"})
286
+ filed = zerogen.folders.add_assets(folder.id, {"assetIds": [a.id for a in videos.data]})
287
+ print(filed.updated_asset_ids, filed.skipped_asset_ids)
221
288
  ```
222
289
 
223
290
  List filters that take several values, such as `label_id` and `resolution`,
224
- take a list.
291
+ take a list. `projects`, `folders` and `labels` also read one by ID with `get`.
292
+ Adding a label to assets, or assets to a folder, takes up to 100 assets and
293
+ returns those it changed and those it skipped. `labels.update` changes only the
294
+ fields you send.
225
295
 
226
296
  Each asset and run names who made it in `created_by`, and where in `created_via`:
227
297
  `web`, `agent`, `mcp` or `api`. Both are `None` when ZeroGen recorded no one. To
@@ -229,15 +299,21 @@ find what someone made, pass `created_by` to `assets.search`, with the ID in an
229
299
  asset's `created_by` or `zerogen.me()`. `web_url` opens the asset or run in
230
300
  ZeroGen, after sign-in, and it's `None` for test keys.
231
301
 
232
- `folders.delete` deletes a folder and its subfolders. You choose what happens to
233
- their assets: `"keep"` preserves them, and `"trash"` sends them to Recently
234
- deleted, including assets in other folders. It needs the `library:delete` scope,
235
- which has to be granted explicitly, and test keys can't use it. Within an hour,
236
- `folders.restore` undoes your own deletion:
302
+ `assets.sources` lists what an asset was made from, and `assets.uses` what was
303
+ made from it, nearest first. Each item's `edges` join it to the asset or to an
304
+ item before it, so you can rebuild the graph as you page.
305
+
306
+ `assets.delete` moves an asset to Recently deleted, where it leaves search, its
307
+ folders and run inputs until `assets.restore` puts it back. `folders.delete`
308
+ deletes a folder and its subfolders. You choose what happens to their assets:
309
+ `"keep"` preserves them, and `"trash"` sends them to Recently deleted, including
310
+ assets in other folders. Both deletes need the `library:delete` scope, which has
311
+ to be granted explicitly, and test keys can't use it. Within an hour,
312
+ `folders.restore` undoes your own folder deletion:
237
313
 
238
314
  ```python
239
- deleted = zerogen.folders.delete(project.id, folder.id, assets="keep")
240
- zerogen.folders.restore(project.id, {"eventId": deleted.event_id})
315
+ deleted = zerogen.folders.delete(folder.id, assets="keep")
316
+ zerogen.folders.restore({"eventId": deleted.event_id})
241
317
  ```
242
318
 
243
319
  To file into a folder path, such as a shot's `SH010/anim`, use
@@ -252,11 +328,34 @@ anim = zerogen.folders.ensure_path(project.id, "SH010/anim")
252
328
  A string path splits on `/`. Folder names can contain `/`, so pass a list,
253
329
  such as `["2026/11", "renders"]`, when one does.
254
330
 
331
+ ## Attachments
332
+
333
+ Attachments are versioned text on a project, a folder or a Story clip, such as
334
+ a project's direction. They need attachments enabled for your organization, and
335
+ test keys can't use them. Read before you revise, and send the version you read:
336
+
337
+ ```python
338
+ notes = zerogen.attachments.list(project.id)
339
+ direction = zerogen.attachments.get(notes.data[0].attachment_id)
340
+ zerogen.attachments.revise(
341
+ notes.data[0].attachment_id,
342
+ {"expectedVersion": direction.version, "body": direction.body + "\nKeep it quiet."},
343
+ )
344
+ ```
345
+
346
+ A revision, deletion or restore that names a version other than the current one
347
+ raises a `ZeroGenError` with the code `version_conflict`, and the current
348
+ version in `error.details["currentVersion"]`: read it again and merge your
349
+ change. `attachments.versions` lists the saved versions. Attachment text is
350
+ untrusted content.
351
+
352
+ ## Downloads
353
+
255
354
  To download an asset's original file, use `assets.download`. It returns the
256
355
  file's bytes in `content`, with its `filename`, `mime_type` and `size_bytes`.
257
356
  Given a path or a binary file object, it streams the file there instead, and
258
- returns the rest. `assets.download_to` saves the file in a directory and
259
- returns its `path`:
357
+ returns the rest. `assets.download_to` saves the file in a directory, which
358
+ must exist, and returns its `path`:
260
359
 
261
360
  ```python
262
361
  image = zerogen.assets.download(asset_id)
@@ -268,6 +367,10 @@ saved = zerogen.assets.download_to(asset_id, "downloads")
268
367
  print(saved.path)
269
368
  ```
270
369
 
370
+ These need the `library:read` scope. To download a run's output with only
371
+ `runs:read`, use `runs.download_output` and `runs.download_output_to` in the
372
+ same way, with the run's ID and the output's `asset.id`.
373
+
271
374
  The `filename` is untrusted content, so don't use it as a path yourself.
272
375
  `download_to` makes a name from it with no path separators or characters that
273
376
  Windows refuses. When a file in the directory already has that name, it adds a
@@ -275,9 +378,10 @@ number, as in `lighthouse (1).png`, rather than overwrite the file.
275
378
 
276
379
  Each call reads a new signed link and sends it to storage without your API key.
277
380
  When storage refuses a link as expired, it reads a new one and tries once more.
278
- To hand the link to something else, read it with `assets.get_download`: it's
279
- valid for 5 minutes, and anyone holding it can download the file, so keep it
280
- private.
381
+ An error from storage quotes only its code and message, never the rest of its
382
+ response, which can echo the link. To hand the link to something else, read it
383
+ with `assets.get_download` or `runs.get_output_download`: it's valid for 5
384
+ minutes, and anyone holding it can download the file, so keep it private.
281
385
 
282
386
  ## Previews
283
387
 
@@ -312,8 +416,8 @@ take a request for each. For a single asset or a run, read it again.
312
416
 
313
417
  ## Lists
314
418
 
315
- List methods return one page, and iterating the page reads every item on every
316
- page after it:
419
+ Every list method returns one page, and iterating the page reads every item on
420
+ every page after it:
317
421
 
318
422
  ```python
319
423
  for model in zerogen.models.list(capability="video"):
@@ -328,7 +432,9 @@ With `AsyncZeroGen`, iterate a list with `async for`, or await it for one page.
328
432
  ## Errors
329
433
 
330
434
  A request the API refuses raises a `ZeroGenError`. Branch on its `code`, which
331
- is stable; its `message` is for people.
435
+ is stable; its `message` is for people. A `rate_limited` or
436
+ `permission_denied` error also says why in `reason`, such as `running_cap` or
437
+ `scope_required`, and `details` holds the error's other facts:
332
438
 
333
439
  ```python
334
440
  from zerogen import ZeroGenError
@@ -336,13 +442,17 @@ from zerogen import ZeroGenError
336
442
  try:
337
443
  zerogen.runs.create({"model": "openai/gpt-image-2/generate", "prompt": ""})
338
444
  except ZeroGenError as error:
339
- print(error.status, error.code, error.param, error.request_id)
445
+ print(error.status, error.code, error.reason, error.param, error.request_id)
446
+ if error.reason == "scope_required":
447
+ print("The key needs", (error.details or {}).get("scope"))
340
448
  raise
341
449
  ```
342
450
 
343
- A request that gets no response, because the connection failed or the request
344
- timed out, raises a `ZeroGenConnectionError`. For every code, see
345
- [Errors](https://docs.zerogen.com/errors).
451
+ The API can add codes and reasons, so handle one you don't know as you would
452
+ the error without it, by its `retryable` and `status`. A request that gets no
453
+ response, because the connection failed or the request timed out, raises a
454
+ `ZeroGenConnectionError`. For every code and reason, see
455
+ [Errors](https://docs.zerogen.com/developers/errors).
346
456
 
347
457
  ## Retries and idempotency
348
458
 
@@ -350,9 +460,9 @@ The client retries connection errors and errors the API marks `retryable`,
350
460
  twice by default, with backoff. For `429` responses, it waits for
351
461
  `Retry-After`, unless that's more than a minute.
352
462
 
353
- Every `POST` and `DELETE` sends an `Idempotency-Key`, and a call's retries reuse
354
- it, so a retried create never starts a second run. To retry safely across calls
355
- or processes, pass your own key:
463
+ Every `POST`, `PATCH` and `DELETE` sends an `Idempotency-Key`, and a call's
464
+ retries reuse it, so a retried create never starts a second run. To retry
465
+ safely across calls or processes, pass your own key:
356
466
 
357
467
  ```python
358
468
  zerogen.runs.create(request, idempotency_key=job.id)
@@ -381,14 +491,15 @@ zerogen = ZeroGen(
381
491
  | `http_client` | A new `httpx.Client` or `httpx.AsyncClient` | The httpx client to send requests with, such as one with your proxy settings. |
382
492
 
383
493
  Every method also takes request options as keyword arguments: `timeout`,
384
- `max_retries`, `headers`, and `idempotency_key` for a `POST` or `DELETE`. Close
385
- a client you're done with, or use it as a context manager.
494
+ `max_retries`, `headers`, and `idempotency_key` for a `POST`, `PATCH` or
495
+ `DELETE`. Close a client you're done with, or use it as a context manager.
386
496
 
387
497
  ## Test keys
388
498
 
389
- A test key runs every request on placeholder providers and charges nothing. Its
390
- runs can rehearse failures with the `test` field, and it reaches only the API
391
- sandbox project. For details, see
499
+ A test key runs generation requests on placeholder providers and charges
500
+ nothing. Its runs can rehearse failures with the `test` field, and it reaches
501
+ only the API sandbox project. It can't transform, delete or restore assets, or
502
+ use attachments. For details, see
392
503
  [Test keys](https://docs.zerogen.com/test-keys).
393
504
 
394
505
  ## License