zerogen 0.1.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.
zerogen-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ZeroGen LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
zerogen-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,207 @@
1
+ Metadata-Version: 2.4
2
+ Name: zerogen
3
+ Version: 0.1.0
4
+ Summary: The official Python library for the ZeroGen API
5
+ Keywords: zerogen,generative-ai,image-generation,video-generation,api
6
+ Author: ZeroGen LLC
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 4 - Beta
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Operating System :: OS Independent
12
+ Classifier: Programming Language :: Python :: 3
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Programming Language :: Python :: 3.14
19
+ Classifier: Typing :: Typed
20
+ Requires-Dist: anyio>=4.5
21
+ Requires-Dist: httpx>=0.27,<1
22
+ Requires-Dist: pydantic>=2.11,<3
23
+ Requires-Dist: typing-extensions>=4.12
24
+ Requires-Python: >=3.10
25
+ Project-URL: Homepage, https://github.com/zerogeneration/zerogen-python
26
+ Project-URL: Documentation, https://docs.zerogen.com
27
+ Project-URL: Issues, https://github.com/zerogeneration/zerogen-python/issues
28
+ Project-URL: Changelog, https://github.com/zerogeneration/zerogen-python/blob/main/CHANGELOG.md
29
+ Description-Content-Type: text/markdown
30
+
31
+ # ZeroGen Python library
32
+
33
+ The official Python client for the [ZeroGen API](https://docs.zerogen.com). It
34
+ runs on Python 3.10 or later, has a synchronous and an asynchronous client, and
35
+ is built on [httpx](https://www.python-httpx.org) and
36
+ [pydantic](https://docs.pydantic.dev).
37
+
38
+ ```bash
39
+ pip install zerogen
40
+ ```
41
+
42
+ The ZeroGen API refuses requests from browsers, so keep your API key on your
43
+ server.
44
+
45
+ ## Usage
46
+
47
+ Create an API key in ZeroGen under **Settings → API keys**, and set it as
48
+ `ZEROGEN_API_KEY`.
49
+
50
+ ```python
51
+ from zerogen import ZeroGen
52
+
53
+ zerogen = ZeroGen() # Reads ZEROGEN_API_KEY.
54
+
55
+ generation = zerogen.generations.create_and_wait(
56
+ {"model": "openai/gpt-image-2/generate", "prompt": "A lighthouse at dawn"}
57
+ )
58
+
59
+ for output in generation.outputs:
60
+ if output.asset:
61
+ print(output.asset.id, output.asset.mime_type)
62
+ ```
63
+
64
+ `create_and_wait` starts a generation and returns it when it ends. A generation
65
+ that fails returns too, so check its `status`, and each output's. Each output's
66
+ asset is in your organization's Library, in the generation's project: your team
67
+ can open and download it in ZeroGen, and you can send its ID as an input to a
68
+ later generation. To start a generation without waiting, use `create`, then
69
+ `get` or `wait_for` with its `id`.
70
+
71
+ A request body is a dict with the API's own field names, such as `projectId`
72
+ and `maxCostMicroUsd`, exactly as the
73
+ [API reference](https://docs.zerogen.com/api-reference/overview) shows it. Each
74
+ response is a pydantic model with snake_case attributes, such as
75
+ `generation.project_id`. Both are typed from the API's
76
+ [OpenAPI document](https://api.zerogen.com/v1/openapi.json), so your editor
77
+ completes and checks them. Each model takes its own parameters: read a model's
78
+ request schema with `zerogen.models.get(id)`.
79
+
80
+ ## Async
81
+
82
+ `AsyncZeroGen` has the same methods, to await:
83
+
84
+ ```python
85
+ import asyncio
86
+
87
+ from zerogen import AsyncZeroGen
88
+
89
+
90
+ async def main() -> None:
91
+ async with AsyncZeroGen() as zerogen:
92
+ generation = await zerogen.generations.create_and_wait(
93
+ {"model": "openai/gpt-image-2/generate", "prompt": "A lighthouse at dawn"}
94
+ )
95
+ print(generation.status)
96
+
97
+
98
+ asyncio.run(main())
99
+ ```
100
+
101
+ Cancel the task to stop a `create_and_wait` or `wait_for` from waiting; the
102
+ generation keeps running.
103
+
104
+ ## Inputs
105
+
106
+ Give a generation an input by asset ID or by `https` URL. To upload a file, use
107
+ `uploads.upload`, which returns when the asset is ready:
108
+
109
+ ```python
110
+ upload = zerogen.uploads.upload("storyboard.png")
111
+
112
+ generation = zerogen.generations.create_and_wait(
113
+ {
114
+ "model": "openai/gpt-image-2/edit",
115
+ "prompt": "Turn the sky into a sunset",
116
+ "inputs": [{"role": "source", "asset": upload.asset_id}],
117
+ }
118
+ )
119
+ ```
120
+
121
+ `upload` takes a path, the file's `bytes`, or a binary file object that can
122
+ seek. It takes the media type from the filename's extension, or from
123
+ `content_type`. It sends the file's SHA-256 digest, so a file the project
124
+ already has is reused instead of uploaded again.
125
+
126
+ ## Lists
127
+
128
+ List methods return one page, and iterating the page reads every item on every
129
+ page after it:
130
+
131
+ ```python
132
+ for model in zerogen.models.list(capability="video"):
133
+ print(model.id)
134
+
135
+ page = zerogen.generations.list(limit=20)
136
+ print(page.data, page.next_cursor)
137
+ ```
138
+
139
+ With `AsyncZeroGen`, iterate a list with `async for`, or await it for one page.
140
+
141
+ ## Errors
142
+
143
+ A request the API refuses raises a `ZeroGenError`. Branch on its `code`, which
144
+ is stable; its `message` is for people.
145
+
146
+ ```python
147
+ from zerogen import ZeroGenError
148
+
149
+ try:
150
+ zerogen.generations.create({"model": "openai/gpt-image-2/generate", "prompt": ""})
151
+ except ZeroGenError as error:
152
+ print(error.status, error.code, error.param, error.request_id)
153
+ raise
154
+ ```
155
+
156
+ A request that gets no response, because the connection failed or the request
157
+ timed out, raises a `ZeroGenConnectionError`. For every code, see
158
+ [Errors](https://docs.zerogen.com/errors).
159
+
160
+ ## Retries and idempotency
161
+
162
+ The client retries connection errors and errors the API marks `retryable`,
163
+ twice by default, with backoff. For `429` responses, it waits for
164
+ `Retry-After`, unless that's more than a minute.
165
+
166
+ Every `POST` sends an `Idempotency-Key`, and a call's retries reuse it, so a
167
+ retried create never starts a second generation. To retry safely across calls
168
+ or processes, pass your own key:
169
+
170
+ ```python
171
+ zerogen.generations.create(request, idempotency_key=job.id)
172
+ ```
173
+
174
+ ## Options
175
+
176
+ ```python
177
+ import os
178
+
179
+ zerogen = ZeroGen(
180
+ api_key=os.environ["ZEROGEN_API_KEY"],
181
+ max_retries=2,
182
+ timeout=120, # Seconds per attempt. Waits on a generation add their wait.
183
+ )
184
+ ```
185
+
186
+ | Option | Default | Description |
187
+ | --- | --- | --- |
188
+ | `api_key` | `ZEROGEN_API_KEY` | The API key. |
189
+ | `base_url` | `ZEROGEN_BASE_URL`, then `https://api.zerogen.com/v1` | The API's base URL. |
190
+ | `max_retries` | `2` | Retries for each request. |
191
+ | `timeout` | `120` | Seconds httpx waits on each step of an attempt. A request that waits on a generation gets its wait added. |
192
+ | `default_headers` | None | Headers to send with every request. |
193
+ | `http_client` | A new `httpx.Client` or `httpx.AsyncClient` | The httpx client to send requests with, such as one with your proxy settings. |
194
+
195
+ Every method also takes request options as keyword arguments: `timeout`,
196
+ `max_retries`, `headers`, and `idempotency_key` for a `POST`. Close a client
197
+ you're done with, or use it as a context manager.
198
+
199
+ ## Test keys
200
+
201
+ A test key runs every request on placeholder providers and charges nothing. Its
202
+ generations can rehearse failures with the `test` field. For details, see
203
+ [Test keys](https://docs.zerogen.com/test-keys).
204
+
205
+ ## License
206
+
207
+ MIT
@@ -0,0 +1,177 @@
1
+ # ZeroGen Python library
2
+
3
+ The official Python client for the [ZeroGen API](https://docs.zerogen.com). It
4
+ runs on Python 3.10 or later, has a synchronous and an asynchronous client, and
5
+ is built on [httpx](https://www.python-httpx.org) and
6
+ [pydantic](https://docs.pydantic.dev).
7
+
8
+ ```bash
9
+ pip install zerogen
10
+ ```
11
+
12
+ The ZeroGen API refuses requests from browsers, so keep your API key on your
13
+ server.
14
+
15
+ ## Usage
16
+
17
+ Create an API key in ZeroGen under **Settings → API keys**, and set it as
18
+ `ZEROGEN_API_KEY`.
19
+
20
+ ```python
21
+ from zerogen import ZeroGen
22
+
23
+ zerogen = ZeroGen() # Reads ZEROGEN_API_KEY.
24
+
25
+ generation = zerogen.generations.create_and_wait(
26
+ {"model": "openai/gpt-image-2/generate", "prompt": "A lighthouse at dawn"}
27
+ )
28
+
29
+ for output in generation.outputs:
30
+ if output.asset:
31
+ print(output.asset.id, output.asset.mime_type)
32
+ ```
33
+
34
+ `create_and_wait` starts a generation and returns it when it ends. A generation
35
+ that fails returns too, so check its `status`, and each output's. Each output's
36
+ asset is in your organization's Library, in the generation's project: your team
37
+ can open and download it in ZeroGen, and you can send its ID as an input to a
38
+ later generation. To start a generation without waiting, use `create`, then
39
+ `get` or `wait_for` with its `id`.
40
+
41
+ A request body is a dict with the API's own field names, such as `projectId`
42
+ and `maxCostMicroUsd`, exactly as the
43
+ [API reference](https://docs.zerogen.com/api-reference/overview) shows it. Each
44
+ response is a pydantic model with snake_case attributes, such as
45
+ `generation.project_id`. Both are typed from the API's
46
+ [OpenAPI document](https://api.zerogen.com/v1/openapi.json), so your editor
47
+ completes and checks them. Each model takes its own parameters: read a model's
48
+ request schema with `zerogen.models.get(id)`.
49
+
50
+ ## Async
51
+
52
+ `AsyncZeroGen` has the same methods, to await:
53
+
54
+ ```python
55
+ import asyncio
56
+
57
+ from zerogen import AsyncZeroGen
58
+
59
+
60
+ async def main() -> None:
61
+ async with AsyncZeroGen() as zerogen:
62
+ generation = await zerogen.generations.create_and_wait(
63
+ {"model": "openai/gpt-image-2/generate", "prompt": "A lighthouse at dawn"}
64
+ )
65
+ print(generation.status)
66
+
67
+
68
+ asyncio.run(main())
69
+ ```
70
+
71
+ Cancel the task to stop a `create_and_wait` or `wait_for` from waiting; the
72
+ generation keeps running.
73
+
74
+ ## Inputs
75
+
76
+ Give a generation an input by asset ID or by `https` URL. To upload a file, use
77
+ `uploads.upload`, which returns when the asset is ready:
78
+
79
+ ```python
80
+ upload = zerogen.uploads.upload("storyboard.png")
81
+
82
+ generation = zerogen.generations.create_and_wait(
83
+ {
84
+ "model": "openai/gpt-image-2/edit",
85
+ "prompt": "Turn the sky into a sunset",
86
+ "inputs": [{"role": "source", "asset": upload.asset_id}],
87
+ }
88
+ )
89
+ ```
90
+
91
+ `upload` takes a path, the file's `bytes`, or a binary file object that can
92
+ seek. It takes the media type from the filename's extension, or from
93
+ `content_type`. It sends the file's SHA-256 digest, so a file the project
94
+ already has is reused instead of uploaded again.
95
+
96
+ ## Lists
97
+
98
+ List methods return one page, and iterating the page reads every item on every
99
+ page after it:
100
+
101
+ ```python
102
+ for model in zerogen.models.list(capability="video"):
103
+ print(model.id)
104
+
105
+ page = zerogen.generations.list(limit=20)
106
+ print(page.data, page.next_cursor)
107
+ ```
108
+
109
+ With `AsyncZeroGen`, iterate a list with `async for`, or await it for one page.
110
+
111
+ ## Errors
112
+
113
+ A request the API refuses raises a `ZeroGenError`. Branch on its `code`, which
114
+ is stable; its `message` is for people.
115
+
116
+ ```python
117
+ from zerogen import ZeroGenError
118
+
119
+ try:
120
+ zerogen.generations.create({"model": "openai/gpt-image-2/generate", "prompt": ""})
121
+ except ZeroGenError as error:
122
+ print(error.status, error.code, error.param, error.request_id)
123
+ raise
124
+ ```
125
+
126
+ A request that gets no response, because the connection failed or the request
127
+ timed out, raises a `ZeroGenConnectionError`. For every code, see
128
+ [Errors](https://docs.zerogen.com/errors).
129
+
130
+ ## Retries and idempotency
131
+
132
+ The client retries connection errors and errors the API marks `retryable`,
133
+ twice by default, with backoff. For `429` responses, it waits for
134
+ `Retry-After`, unless that's more than a minute.
135
+
136
+ Every `POST` sends an `Idempotency-Key`, and a call's retries reuse it, so a
137
+ retried create never starts a second generation. To retry safely across calls
138
+ or processes, pass your own key:
139
+
140
+ ```python
141
+ zerogen.generations.create(request, idempotency_key=job.id)
142
+ ```
143
+
144
+ ## Options
145
+
146
+ ```python
147
+ import os
148
+
149
+ zerogen = ZeroGen(
150
+ api_key=os.environ["ZEROGEN_API_KEY"],
151
+ max_retries=2,
152
+ timeout=120, # Seconds per attempt. Waits on a generation add their wait.
153
+ )
154
+ ```
155
+
156
+ | Option | Default | Description |
157
+ | --- | --- | --- |
158
+ | `api_key` | `ZEROGEN_API_KEY` | The API key. |
159
+ | `base_url` | `ZEROGEN_BASE_URL`, then `https://api.zerogen.com/v1` | The API's base URL. |
160
+ | `max_retries` | `2` | Retries for each request. |
161
+ | `timeout` | `120` | Seconds httpx waits on each step of an attempt. A request that waits on a generation gets its wait added. |
162
+ | `default_headers` | None | Headers to send with every request. |
163
+ | `http_client` | A new `httpx.Client` or `httpx.AsyncClient` | The httpx client to send requests with, such as one with your proxy settings. |
164
+
165
+ Every method also takes request options as keyword arguments: `timeout`,
166
+ `max_retries`, `headers`, and `idempotency_key` for a `POST`. Close a client
167
+ you're done with, or use it as a context manager.
168
+
169
+ ## Test keys
170
+
171
+ A test key runs every request on placeholder providers and charges nothing. Its
172
+ generations can rehearse failures with the `test` field. For details, see
173
+ [Test keys](https://docs.zerogen.com/test-keys).
174
+
175
+ ## License
176
+
177
+ MIT
@@ -0,0 +1,86 @@
1
+ [project]
2
+ name = "zerogen"
3
+ version = "0.1.0"
4
+ description = "The official Python library for the ZeroGen API"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ keywords = [
9
+ "zerogen",
10
+ "generative-ai",
11
+ "image-generation",
12
+ "video-generation",
13
+ "api",
14
+ ]
15
+ classifiers = [
16
+ "Development Status :: 4 - Beta",
17
+ "Intended Audience :: Developers",
18
+ "Operating System :: OS Independent",
19
+ "Programming Language :: Python :: 3",
20
+ "Programming Language :: Python :: 3 :: Only",
21
+ "Programming Language :: Python :: 3.10",
22
+ "Programming Language :: Python :: 3.11",
23
+ "Programming Language :: Python :: 3.12",
24
+ "Programming Language :: Python :: 3.13",
25
+ "Programming Language :: Python :: 3.14",
26
+ "Typing :: Typed",
27
+ ]
28
+ requires-python = ">=3.10"
29
+ dependencies = [
30
+ "anyio>=4.5",
31
+ "httpx>=0.27,<1",
32
+ "pydantic>=2.11,<3",
33
+ "typing-extensions>=4.12",
34
+ ]
35
+
36
+ [[project.authors]]
37
+ name = "ZeroGen LLC"
38
+
39
+ [project.urls]
40
+ Homepage = "https://github.com/zerogeneration/zerogen-python"
41
+ Documentation = "https://docs.zerogen.com"
42
+ Issues = "https://github.com/zerogeneration/zerogen-python/issues"
43
+ Changelog = "https://github.com/zerogeneration/zerogen-python/blob/main/CHANGELOG.md"
44
+
45
+ [dependency-groups]
46
+ dev = [
47
+ "datamodel-code-generator>=0.35",
48
+ "pyright[nodejs]>=1.1.400",
49
+ "pytest>=8.3",
50
+ "ruff>=0.14",
51
+ ]
52
+
53
+ [build-system]
54
+ requires = ["uv_build>=0.13.5,<0.14"]
55
+ build-backend = "uv_build"
56
+
57
+ [tool.ruff]
58
+ line-length = 100
59
+
60
+ [tool.ruff.lint]
61
+ select = [
62
+ "E",
63
+ "W",
64
+ "F",
65
+ "I",
66
+ "UP",
67
+ "B",
68
+ "C4",
69
+ "SIM",
70
+ "PT",
71
+ "RUF",
72
+ ]
73
+ exclude = ["src/zerogen/types/*"]
74
+
75
+ [tool.pyright]
76
+ include = [
77
+ "src",
78
+ "tests",
79
+ "scripts",
80
+ ]
81
+ pythonVersion = "3.10"
82
+ typeCheckingMode = "strict"
83
+ reportPrivateUsage = false
84
+
85
+ [tool.pytest.ini_options]
86
+ testpaths = ["tests"]
@@ -0,0 +1,63 @@
1
+ [project]
2
+ name = "zerogen"
3
+ version = "0.1.0"
4
+ description = "The official Python library for the ZeroGen API"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ authors = [{ name = "ZeroGen LLC" }]
9
+ keywords = ["zerogen", "generative-ai", "image-generation", "video-generation", "api"]
10
+ classifiers = [
11
+ "Development Status :: 4 - Beta",
12
+ "Intended Audience :: Developers",
13
+ "Operating System :: OS Independent",
14
+ "Programming Language :: Python :: 3",
15
+ "Programming Language :: Python :: 3 :: Only",
16
+ "Programming Language :: Python :: 3.10",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Programming Language :: Python :: 3.14",
21
+ "Typing :: Typed",
22
+ ]
23
+ requires-python = ">=3.10"
24
+ dependencies = [
25
+ "anyio>=4.5",
26
+ "httpx>=0.27,<1",
27
+ "pydantic>=2.11,<3",
28
+ "typing-extensions>=4.12",
29
+ ]
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/zerogeneration/zerogen-python"
33
+ Documentation = "https://docs.zerogen.com"
34
+ Issues = "https://github.com/zerogeneration/zerogen-python/issues"
35
+ Changelog = "https://github.com/zerogeneration/zerogen-python/blob/main/CHANGELOG.md"
36
+
37
+ [dependency-groups]
38
+ dev = [
39
+ "datamodel-code-generator>=0.35",
40
+ "pyright[nodejs]>=1.1.400",
41
+ "pytest>=8.3",
42
+ "ruff>=0.14",
43
+ ]
44
+
45
+ [build-system]
46
+ requires = ["uv_build>=0.13.5,<0.14"]
47
+ build-backend = "uv_build"
48
+
49
+ [tool.ruff]
50
+ line-length = 100
51
+
52
+ [tool.ruff.lint]
53
+ select = ["E", "W", "F", "I", "UP", "B", "C4", "SIM", "PT", "RUF"]
54
+ exclude = ["src/zerogen/types/*"]
55
+
56
+ [tool.pyright]
57
+ include = ["src", "tests", "scripts"]
58
+ pythonVersion = "3.10"
59
+ typeCheckingMode = "strict"
60
+ reportPrivateUsage = false
61
+
62
+ [tool.pytest.ini_options]
63
+ testpaths = ["tests"]
@@ -0,0 +1,27 @@
1
+ """The official Python library for the ZeroGen API."""
2
+
3
+ from . import types
4
+ from ._client import AsyncZeroGen, ZeroGen
5
+ from ._errors import ZeroGenConnectionError, ZeroGenError
6
+ from ._options import PostRequestOptions, RequestOptions
7
+ from ._pagination import AsyncPage, AsyncPaginator, Page
8
+ from ._version import __version__
9
+ from .resources.generations import has_ended
10
+ from .resources.uploads import ReadyUpload, UploadSource
11
+
12
+ __all__ = [
13
+ "AsyncPage",
14
+ "AsyncPaginator",
15
+ "AsyncZeroGen",
16
+ "Page",
17
+ "PostRequestOptions",
18
+ "ReadyUpload",
19
+ "RequestOptions",
20
+ "UploadSource",
21
+ "ZeroGen",
22
+ "ZeroGenConnectionError",
23
+ "ZeroGenError",
24
+ "__version__",
25
+ "has_ended",
26
+ "types",
27
+ ]