zebracat 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.
@@ -0,0 +1,7 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyc
4
+ dist/
5
+ build/
6
+ *.egg-info/
7
+ .pytest_cache/
zebracat-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zebracat
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.
@@ -0,0 +1,202 @@
1
+ Metadata-Version: 2.5
2
+ Name: zebracat
3
+ Version: 0.1.0
4
+ Summary: Official Python client for the Zebracat video API
5
+ Project-URL: Homepage, https://zebracat.ai
6
+ Project-URL: Documentation, https://api.zebracat.ai/docs
7
+ Project-URL: Source, https://github.com/zebracatai/zebracat-python
8
+ Author: Zebracat
9
+ License-Expression: MIT
10
+ License-File: LICENSE
11
+ Keywords: ai,api,sdk,video,zebracat
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Multimedia :: Video
17
+ Classifier: Typing :: Typed
18
+ Requires-Python: >=3.9
19
+ Requires-Dist: httpx<1,>=0.24
20
+ Provides-Extra: test
21
+ Requires-Dist: pytest>=7; extra == 'test'
22
+ Description-Content-Type: text/markdown
23
+
24
+ # Zebracat Python SDK
25
+
26
+ The official Python client for the [Zebracat API](https://api.zebracat.ai/docs): make videos with AI from a brief,
27
+ a script or a link, then read, quote, generate and download them.
28
+
29
+ ```bash
30
+ pip install zebracat
31
+ ```
32
+
33
+ Python 3.9 or newer. One dependency: `httpx`.
34
+
35
+ ## Quickstart
36
+
37
+ Create an API key at <https://zebracat.ai/api> and export it:
38
+
39
+ ```bash
40
+ export ZEBRACAT_API_KEY=sk-...
41
+ ```
42
+
43
+ ```python
44
+ from zebracat import Zebracat
45
+
46
+ client = Zebracat() # reads ZEBRACAT_API_KEY
47
+
48
+ # 1. Plan a video. Planning is free; nothing is charged until you generate.
49
+ video = client.create_video(
50
+ brief="How bees make honey",
51
+ auto_generate=False,
52
+ options={"seconds": 30, "aspect": "vertical", "media_type": "ai_video"},
53
+ )
54
+
55
+ # 2. Wait for the plan, then look at the price.
56
+ video = client.wait_for_video(video["task_id"]) # returns at plan_ready
57
+ print(client.quote_video(video["task_id"]))
58
+
59
+ # 3. Generate it (this spends credit) and wait for the file.
60
+ client.generate_video(video["task_id"])
61
+ video = client.wait_for_video(video["task_id"]) # returns at completed
62
+ print(video["video_url"])
63
+ ```
64
+
65
+ Pass `auto_generate=True` to plan and generate in one call; `wait_for_video` then returns once the video is done.
66
+
67
+ ## Every operation is a method
68
+
69
+ Each operation of the [OpenAPI document](openapi/openapi.json) is a method named after its `operationId`:
70
+ `create_video`, `get_video`, `list_videos`, `quote_video`, `generate_video`, `clone_video`, `translate_video`,
71
+ `list_voices`, `list_templates`, `upload_file`, `create_upload_link`, `create_webhook`, `list_capabilities`,
72
+ `get_account`, and the rest.
73
+
74
+ - Path parameters are positional: `client.get_video("6f1c…")`.
75
+ - Query parameters and body fields are keyword arguments: `client.create_video(brief="…", auto_generate=True)`.
76
+ - Leave an argument out to not send it; pass `None` to send JSON `null`. Fields the SDK does not know yet go in
77
+ `extra_body={...}`.
78
+ - Answers are plain `dict`s, typed as `TypedDict`s in `zebracat.types` for your editor.
79
+ - Files (`upload_file`, `create_clone_voice`, `upload_to_link`) take bytes, an open binary file, or
80
+ `(filename, bytes, content_type)`.
81
+ - Operations the API marks deprecated still work and raise a `DeprecationWarning`.
82
+
83
+ ## Uploading a file
84
+
85
+ `upload_file` takes a picture in one call. For a video to translate, clone or swap, or a voice sample, use a one-time
86
+ upload link: `upload_with_link` asks for the link (`create_upload_link`) and sends the file to it.
87
+
88
+ ```python
89
+ stored = client.upload_with_link("talk.mp4", use="translate") # a local path, bytes or an open file
90
+ video = client.translate_video(video_url=stored["url"], target_language="es")
91
+ ```
92
+
93
+ `use` is `picture`, `translate`, `clone`, `swap` or `voice_clone`; it sets the accepted types and the size cap.
94
+
95
+ ## Authentication
96
+
97
+ ```python
98
+ Zebracat(api_key="sk-...") # X-API-KEY, billed from the API balance
99
+
100
+ Zebracat( # OAuth: Authorization: Bearer zoa_..., billed from plan credits
101
+ access_token="zoa_...",
102
+ refresh_token="zor_...",
103
+ client_id="your-oauth-client-id",
104
+ client_secret=None, # only for confidential clients
105
+ on_token_refresh=lambda tokens: save(tokens),
106
+ )
107
+ ```
108
+
109
+ With a refresh token, a `401` makes the client swap it for a new pair once (`POST /api/oauth/token`, the API rotates
110
+ both tokens) and repeat the call. `on_token_refresh` receives the new tokens so you can store them.
111
+
112
+ `ZEBRACAT_BASE_URL` (or `base_url=`) points the client at another server.
113
+
114
+ ## Retries
115
+
116
+ A call is repeated up to `max_retries` times (default 3) when the API answers `429`, `500`, `502`, `503` or `504`,
117
+ or the connection drops:
118
+
119
+ - A `Retry-After` header is honoured. A wait longer than `max_retry_wait` (default 60 s, e.g. a daily cap) is raised
120
+ as `RateLimitError` with `retry_after` instead of slept through.
121
+ - Without `Retry-After` the wait is 0.5 s, 1 s, 2 s… (at most 8 s) with jitter.
122
+ - A `429` is always retried: the API refused before doing anything.
123
+ - A `5xx` or a dropped connection is retried only when resending cannot do the work twice: reads, `PUT`, `DELETE`,
124
+ and the paid POSTs whose server replays the first answer for a repeated `Idempotency-Key` (`create_video`,
125
+ `clone_video`, `translate_video` and the v1 creators). Other POSTs raise at once, so a charge is never repeated.
126
+
127
+ Per call: `request_options={"max_retries": 0, "timeout": 120, "headers": {...}}`.
128
+
129
+ ## Idempotency keys
130
+
131
+ Every POST that spends money (it can answer `402`, or it buys credit) sends an `Idempotency-Key`. The SDK makes one
132
+ per call and reuses it across that call's retries. Pass your own to make a retry from your side safe too:
133
+
134
+ ```python
135
+ client.create_video(brief="…", auto_generate=True, idempotency_key=f"order-{order_id}")
136
+ ```
137
+
138
+ The same key with a different body answers `422 idempotency_key_reused`.
139
+
140
+ ## Waiting for a video
141
+
142
+ `wait_for_video(task_id, timeout=1800, poll_interval=None, on_update=None)` reads the video again after the
143
+ `poll_after_s` seconds the API gives (falling back to 10–30 s per phase on an API that does not send it). It returns
144
+ when nothing more happens on its own:
145
+
146
+ | phase | what you do next |
147
+ |---|---|
148
+ | `completed` | `video["video_url"]` is the file; `download_video_file(task_id)` returns the URL as well |
149
+ | `plan_ready` | show `quote_video(task_id)`, then `generate_video(task_id)` and wait again |
150
+ | `needs_input` | answer `video["question"]` with `answer_video_question(task_id, ...)` and wait again |
151
+
152
+ It raises `VideoFailedError` (`.video`, `.phase`, `.error`) when the video fails or is cancelled, and
153
+ `WaitTimeoutError` (`.video`) when `timeout` passes first; the video keeps going on our side.
154
+
155
+ ## Errors
156
+
157
+ Every error from the API is a subclass of `zebracat.APIError` and carries the public error envelope:
158
+
159
+ ```python
160
+ from zebracat import InsufficientFundsError, RateLimitError, APIError
161
+
162
+ try:
163
+ client.generate_video(task_id)
164
+ except InsufficientFundsError as e:
165
+ print("Add credit:", e.topup_url)
166
+ except RateLimitError as e:
167
+ print("Try again in", e.retry_after, "s")
168
+ except APIError as e:
169
+ print(e.status_code, e.code, e.hint, e.request_id)
170
+ ```
171
+
172
+ | status | class |
173
+ |---|---|
174
+ | 400, 422 | `BadRequestError` (`field`, `allowed_values`, `errors`) |
175
+ | 401 | `AuthenticationError` |
176
+ | 402 | `InsufficientFundsError` (`topup_url`) |
177
+ | 403 | `PermissionDeniedError` (`upgrade_url`) |
178
+ | 404, 410 | `NotFoundError` |
179
+ | 409 | `ConflictError` |
180
+ | 429 | `RateLimitError` (`retry_after`) |
181
+ | 5xx | `InternalServerError` |
182
+ | no answer | `APIConnectionError`, `APITimeoutError` |
183
+
184
+ `request_id` is the id to quote to support: the API's `request_id` (also the `X-Request-ID` header). The SDK sends
185
+ an `X-Request-ID` of its own on every call, so even a connection error has one.
186
+
187
+ ## Development
188
+
189
+ ```bash
190
+ uv venv && uv pip install -e '.[test]'
191
+ python scripts/generate.py # regenerate src/zebracat/_generated from openapi/openapi.json
192
+ python scripts/generate.py --check # CI: fails when the generated code is out of date
193
+ pytest # runs against a local stub server, no network
194
+ ```
195
+
196
+ `openapi/openapi.json` comes from the backend: `python manage.py spectacular --format openapi-json --file
197
+ openapi.json` (or download `https://api.zebracat.ai/docs/openapi.json`). Copy it here, regenerate, commit both.
198
+
199
+ ## Releasing
200
+
201
+ Bump `src/zebracat/_version.py`, commit, tag `vX.Y.Z` and push the tag. `.github/workflows/release.yml` tests,
202
+ builds and publishes to PyPI with trusted publishing (GitHub OIDC; no token is stored anywhere).
@@ -0,0 +1,179 @@
1
+ # Zebracat Python SDK
2
+
3
+ The official Python client for the [Zebracat API](https://api.zebracat.ai/docs): make videos with AI from a brief,
4
+ a script or a link, then read, quote, generate and download them.
5
+
6
+ ```bash
7
+ pip install zebracat
8
+ ```
9
+
10
+ Python 3.9 or newer. One dependency: `httpx`.
11
+
12
+ ## Quickstart
13
+
14
+ Create an API key at <https://zebracat.ai/api> and export it:
15
+
16
+ ```bash
17
+ export ZEBRACAT_API_KEY=sk-...
18
+ ```
19
+
20
+ ```python
21
+ from zebracat import Zebracat
22
+
23
+ client = Zebracat() # reads ZEBRACAT_API_KEY
24
+
25
+ # 1. Plan a video. Planning is free; nothing is charged until you generate.
26
+ video = client.create_video(
27
+ brief="How bees make honey",
28
+ auto_generate=False,
29
+ options={"seconds": 30, "aspect": "vertical", "media_type": "ai_video"},
30
+ )
31
+
32
+ # 2. Wait for the plan, then look at the price.
33
+ video = client.wait_for_video(video["task_id"]) # returns at plan_ready
34
+ print(client.quote_video(video["task_id"]))
35
+
36
+ # 3. Generate it (this spends credit) and wait for the file.
37
+ client.generate_video(video["task_id"])
38
+ video = client.wait_for_video(video["task_id"]) # returns at completed
39
+ print(video["video_url"])
40
+ ```
41
+
42
+ Pass `auto_generate=True` to plan and generate in one call; `wait_for_video` then returns once the video is done.
43
+
44
+ ## Every operation is a method
45
+
46
+ Each operation of the [OpenAPI document](openapi/openapi.json) is a method named after its `operationId`:
47
+ `create_video`, `get_video`, `list_videos`, `quote_video`, `generate_video`, `clone_video`, `translate_video`,
48
+ `list_voices`, `list_templates`, `upload_file`, `create_upload_link`, `create_webhook`, `list_capabilities`,
49
+ `get_account`, and the rest.
50
+
51
+ - Path parameters are positional: `client.get_video("6f1c…")`.
52
+ - Query parameters and body fields are keyword arguments: `client.create_video(brief="…", auto_generate=True)`.
53
+ - Leave an argument out to not send it; pass `None` to send JSON `null`. Fields the SDK does not know yet go in
54
+ `extra_body={...}`.
55
+ - Answers are plain `dict`s, typed as `TypedDict`s in `zebracat.types` for your editor.
56
+ - Files (`upload_file`, `create_clone_voice`, `upload_to_link`) take bytes, an open binary file, or
57
+ `(filename, bytes, content_type)`.
58
+ - Operations the API marks deprecated still work and raise a `DeprecationWarning`.
59
+
60
+ ## Uploading a file
61
+
62
+ `upload_file` takes a picture in one call. For a video to translate, clone or swap, or a voice sample, use a one-time
63
+ upload link: `upload_with_link` asks for the link (`create_upload_link`) and sends the file to it.
64
+
65
+ ```python
66
+ stored = client.upload_with_link("talk.mp4", use="translate") # a local path, bytes or an open file
67
+ video = client.translate_video(video_url=stored["url"], target_language="es")
68
+ ```
69
+
70
+ `use` is `picture`, `translate`, `clone`, `swap` or `voice_clone`; it sets the accepted types and the size cap.
71
+
72
+ ## Authentication
73
+
74
+ ```python
75
+ Zebracat(api_key="sk-...") # X-API-KEY, billed from the API balance
76
+
77
+ Zebracat( # OAuth: Authorization: Bearer zoa_..., billed from plan credits
78
+ access_token="zoa_...",
79
+ refresh_token="zor_...",
80
+ client_id="your-oauth-client-id",
81
+ client_secret=None, # only for confidential clients
82
+ on_token_refresh=lambda tokens: save(tokens),
83
+ )
84
+ ```
85
+
86
+ With a refresh token, a `401` makes the client swap it for a new pair once (`POST /api/oauth/token`, the API rotates
87
+ both tokens) and repeat the call. `on_token_refresh` receives the new tokens so you can store them.
88
+
89
+ `ZEBRACAT_BASE_URL` (or `base_url=`) points the client at another server.
90
+
91
+ ## Retries
92
+
93
+ A call is repeated up to `max_retries` times (default 3) when the API answers `429`, `500`, `502`, `503` or `504`,
94
+ or the connection drops:
95
+
96
+ - A `Retry-After` header is honoured. A wait longer than `max_retry_wait` (default 60 s, e.g. a daily cap) is raised
97
+ as `RateLimitError` with `retry_after` instead of slept through.
98
+ - Without `Retry-After` the wait is 0.5 s, 1 s, 2 s… (at most 8 s) with jitter.
99
+ - A `429` is always retried: the API refused before doing anything.
100
+ - A `5xx` or a dropped connection is retried only when resending cannot do the work twice: reads, `PUT`, `DELETE`,
101
+ and the paid POSTs whose server replays the first answer for a repeated `Idempotency-Key` (`create_video`,
102
+ `clone_video`, `translate_video` and the v1 creators). Other POSTs raise at once, so a charge is never repeated.
103
+
104
+ Per call: `request_options={"max_retries": 0, "timeout": 120, "headers": {...}}`.
105
+
106
+ ## Idempotency keys
107
+
108
+ Every POST that spends money (it can answer `402`, or it buys credit) sends an `Idempotency-Key`. The SDK makes one
109
+ per call and reuses it across that call's retries. Pass your own to make a retry from your side safe too:
110
+
111
+ ```python
112
+ client.create_video(brief="…", auto_generate=True, idempotency_key=f"order-{order_id}")
113
+ ```
114
+
115
+ The same key with a different body answers `422 idempotency_key_reused`.
116
+
117
+ ## Waiting for a video
118
+
119
+ `wait_for_video(task_id, timeout=1800, poll_interval=None, on_update=None)` reads the video again after the
120
+ `poll_after_s` seconds the API gives (falling back to 10–30 s per phase on an API that does not send it). It returns
121
+ when nothing more happens on its own:
122
+
123
+ | phase | what you do next |
124
+ |---|---|
125
+ | `completed` | `video["video_url"]` is the file; `download_video_file(task_id)` returns the URL as well |
126
+ | `plan_ready` | show `quote_video(task_id)`, then `generate_video(task_id)` and wait again |
127
+ | `needs_input` | answer `video["question"]` with `answer_video_question(task_id, ...)` and wait again |
128
+
129
+ It raises `VideoFailedError` (`.video`, `.phase`, `.error`) when the video fails or is cancelled, and
130
+ `WaitTimeoutError` (`.video`) when `timeout` passes first; the video keeps going on our side.
131
+
132
+ ## Errors
133
+
134
+ Every error from the API is a subclass of `zebracat.APIError` and carries the public error envelope:
135
+
136
+ ```python
137
+ from zebracat import InsufficientFundsError, RateLimitError, APIError
138
+
139
+ try:
140
+ client.generate_video(task_id)
141
+ except InsufficientFundsError as e:
142
+ print("Add credit:", e.topup_url)
143
+ except RateLimitError as e:
144
+ print("Try again in", e.retry_after, "s")
145
+ except APIError as e:
146
+ print(e.status_code, e.code, e.hint, e.request_id)
147
+ ```
148
+
149
+ | status | class |
150
+ |---|---|
151
+ | 400, 422 | `BadRequestError` (`field`, `allowed_values`, `errors`) |
152
+ | 401 | `AuthenticationError` |
153
+ | 402 | `InsufficientFundsError` (`topup_url`) |
154
+ | 403 | `PermissionDeniedError` (`upgrade_url`) |
155
+ | 404, 410 | `NotFoundError` |
156
+ | 409 | `ConflictError` |
157
+ | 429 | `RateLimitError` (`retry_after`) |
158
+ | 5xx | `InternalServerError` |
159
+ | no answer | `APIConnectionError`, `APITimeoutError` |
160
+
161
+ `request_id` is the id to quote to support: the API's `request_id` (also the `X-Request-ID` header). The SDK sends
162
+ an `X-Request-ID` of its own on every call, so even a connection error has one.
163
+
164
+ ## Development
165
+
166
+ ```bash
167
+ uv venv && uv pip install -e '.[test]'
168
+ python scripts/generate.py # regenerate src/zebracat/_generated from openapi/openapi.json
169
+ python scripts/generate.py --check # CI: fails when the generated code is out of date
170
+ pytest # runs against a local stub server, no network
171
+ ```
172
+
173
+ `openapi/openapi.json` comes from the backend: `python manage.py spectacular --format openapi-json --file
174
+ openapi.json` (or download `https://api.zebracat.ai/docs/openapi.json`). Copy it here, regenerate, commit both.
175
+
176
+ ## Releasing
177
+
178
+ Bump `src/zebracat/_version.py`, commit, tag `vX.Y.Z` and push the tag. `.github/workflows/release.yml` tests,
179
+ builds and publishes to PyPI with trusted publishing (GitHub OIDC; no token is stored anywhere).