zilapi 0.5.0__py3-none-any.whl
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.
- zilapi/__init__.py +109 -0
- zilapi/_base.py +283 -0
- zilapi/_client.py +301 -0
- zilapi/_downloads.py +260 -0
- zilapi/_uploads.py +193 -0
- zilapi/_version.py +3 -0
- zilapi/errors.py +153 -0
- zilapi/py.typed +0 -0
- zilapi/resources/__init__.py +3 -0
- zilapi/resources/audio.py +117 -0
- zilapi/resources/credits.py +27 -0
- zilapi/resources/files.py +291 -0
- zilapi/resources/images.py +375 -0
- zilapi/resources/jobs.py +286 -0
- zilapi/resources/models.py +40 -0
- zilapi/types.py +499 -0
- zilapi-0.5.0.dist-info/METADATA +387 -0
- zilapi-0.5.0.dist-info/RECORD +20 -0
- zilapi-0.5.0.dist-info/WHEEL +4 -0
- zilapi-0.5.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: zilapi
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Typed sync and async Python clients for the ZilAPI media AI API (background removal, audio cleanup)
|
|
5
|
+
Project-URL: Homepage, https://zilapi.com
|
|
6
|
+
Project-URL: Documentation, https://zilapi.com/docs
|
|
7
|
+
Project-URL: Repository, https://github.com/inverse-ai/zilapi-python
|
|
8
|
+
Project-URL: Issues, https://github.com/inverse-ai/zilapi-python/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/inverse-ai/zilapi-python/blob/main/CHANGELOG.md
|
|
10
|
+
Author-email: ZilAPI <support@zilapi.com>
|
|
11
|
+
License: MIT
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: api,audio,background-removal,image,noise-reduction,remove-background,sdk,zilapi
|
|
14
|
+
Classifier: Development Status :: 4 - Beta
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
24
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
25
|
+
Classifier: Topic :: Multimedia :: Sound/Audio
|
|
26
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.9
|
|
29
|
+
Requires-Dist: httpx<1,>=0.25
|
|
30
|
+
Provides-Extra: dev
|
|
31
|
+
Requires-Dist: mypy==2.4.0; (python_version >= '3.10') and extra == 'dev'
|
|
32
|
+
Requires-Dist: pytest-asyncio==0.24.0; (python_version < '3.10') and extra == 'dev'
|
|
33
|
+
Requires-Dist: pytest-asyncio==1.4.0; (python_version >= '3.10') and extra == 'dev'
|
|
34
|
+
Requires-Dist: pytest==8.3.5; (python_version < '3.10') and extra == 'dev'
|
|
35
|
+
Requires-Dist: pytest==9.1.1; (python_version >= '3.10') and extra == 'dev'
|
|
36
|
+
Requires-Dist: respx==0.23.1; extra == 'dev'
|
|
37
|
+
Requires-Dist: ruff==0.16.10; extra == 'dev'
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
|
|
40
|
+
# ZilAPI Python SDK
|
|
41
|
+
|
|
42
|
+
`zilapi` 0.5.0 supports Python 3.9-3.13 with synchronous and asynchronous clients.
|
|
43
|
+
Its only runtime dependency is `httpx`. Responses are frozen, typed dataclasses;
|
|
44
|
+
unknown fields are preserved in `.raw`. Timestamps are timezone-aware `datetime` objects.
|
|
45
|
+
`JobStatus` and `FileStatus` document known states; status fields accept new server values.
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
pip install zilapi
|
|
49
|
+
export ZILAPI_KEY="<your API key>"
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Create a key at https://zilapi.com/dashboard/keys. API reference: https://zilapi.com/docs/.
|
|
53
|
+
The client reads `ZILAPI_KEY`; `ZILAPI_API_KEY`, the older name, still works when `ZILAPI_KEY` is unset.
|
|
54
|
+
|
|
55
|
+
## Quickstart: remove a background
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from zilapi import ZilAPI
|
|
59
|
+
|
|
60
|
+
with ZilAPI() as client:
|
|
61
|
+
client.images.remove_background("photo.jpg").save("photo-cutout.png")
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
That uploads the image, waits for the job (images take seconds) and saves the cut-out PNG with a
|
|
65
|
+
transparent background. See [Background removal](#background-removal) for the mask, URLs and async use.
|
|
66
|
+
|
|
67
|
+
The API host is `https://api.zilapi.com` for both kinds of key. Test keys (`zil_test_…`) are
|
|
68
|
+
free, accept uploads up to 25 MB, and produce canned output (an MP3, or a cut-out and mask)
|
|
69
|
+
almost immediately. Live keys (`zil_live_…`) run real processing and incur charges.
|
|
70
|
+
|
|
71
|
+
## Synchronous flow
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from zilapi import ZilAPI
|
|
75
|
+
|
|
76
|
+
with ZilAPI() as client:
|
|
77
|
+
me = client.me()
|
|
78
|
+
models = client.models.list()
|
|
79
|
+
model = client.models.get("zilapi/nr-4.1")
|
|
80
|
+
credits = client.credits.retrieve()
|
|
81
|
+
|
|
82
|
+
file = client.files.create("recording.wav") # Upload and wait for validation.
|
|
83
|
+
job = client.audio.denoise(file=file) # Defaults to zilapi/nr-4.1.
|
|
84
|
+
job = client.jobs.wait(job)
|
|
85
|
+
if job.succeeded:
|
|
86
|
+
path = client.jobs.download(job, "clean.mp3")
|
|
87
|
+
else:
|
|
88
|
+
print(job.status, job.error)
|
|
89
|
+
client.files.delete(file.id)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Asynchronous flow
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
import asyncio
|
|
96
|
+
from zilapi import AsyncZilAPI
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
async def main() -> None:
|
|
100
|
+
async with AsyncZilAPI() as client:
|
|
101
|
+
file = await client.files.create("recording.wav")
|
|
102
|
+
job = await client.audio.denoise(file=file)
|
|
103
|
+
job = await client.jobs.wait(job, timeout=3600)
|
|
104
|
+
if job.succeeded:
|
|
105
|
+
await client.jobs.download(job, "clean-async.mp3")
|
|
106
|
+
else:
|
|
107
|
+
print(job.status, job.error)
|
|
108
|
+
await client.files.delete(file.id)
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
asyncio.run(main())
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
File creation also accepts bytes and seekable binary streams. Supply `filename`
|
|
115
|
+
for bytes or unnamed streams, and `content_type` when the extension is unknown.
|
|
116
|
+
Streams upload from their current position to the end, and caller-owned streams
|
|
117
|
+
remain open and retain their position. Paths stream in bounded
|
|
118
|
+
chunks; multipart uploads use at most `upload_concurrency=4` concurrent requests.
|
|
119
|
+
The async client performs bounded local file reads/writes synchronously; network
|
|
120
|
+
operations and retry/poll delays are asynchronous.
|
|
121
|
+
|
|
122
|
+
Use `wait=False` to return the validating file immediately, then
|
|
123
|
+
`client.files.wait_until_ready(file.id, timeout=600)` to wait separately.
|
|
124
|
+
`client.files.retrieve(file.id)` fetches current status. Upload failures trigger a
|
|
125
|
+
best-effort deletion of the partial file. When you pass your own
|
|
126
|
+
`idempotency_key` and re-run `files.create()` after an interrupted call (for example a
|
|
127
|
+
timeout or a crash after the upload finished), an upload that already reached the server
|
|
128
|
+
is not sent again: the SDK resumes waiting for validation. If the upload window has
|
|
129
|
+
expired, or the file was deleted (the SDK deletes the file when a storage upload fails
|
|
130
|
+
with `UploadError`), it raises `UploadError`; create the file again with a new key. File validation polls start at 0.5 seconds,
|
|
131
|
+
grow by 1.5, and cap at 5 seconds.
|
|
132
|
+
|
|
133
|
+
`jobs.wait()` fetches immediately, then polls every 15 seconds for the first five
|
|
134
|
+
minutes and every 60 seconds thereafter. Its default deadline is 24 hours;
|
|
135
|
+
`timeout=None` waits indefinitely. Failed and canceled jobs are returned, not raised.
|
|
136
|
+
A wait deadline bounds polling delays; an in-flight HTTP request still uses the
|
|
137
|
+
client's HTTP timeout. `jobs.cancel(job.id)` cancels queued jobs.
|
|
138
|
+
|
|
139
|
+
`jobs.output(job.id)` returns a short-lived signed link; its `expires_at` says when it stops
|
|
140
|
+
working. Downloads
|
|
141
|
+
stream to a temporary file in the destination directory, then replace the target
|
|
142
|
+
atomically. The parent directory must exist. Pass a directory to use the output's
|
|
143
|
+
sanitized filename; use `overwrite=True` to replace an existing file. Pass `name=` (for
|
|
144
|
+
example `"instrumental"`) to pick one of several outputs.
|
|
145
|
+
|
|
146
|
+
Each download is checked for completeness: the bytes received must match the job's stored
|
|
147
|
+
output size and the response's `Content-Length`. A short body or a dropped connection is
|
|
148
|
+
retried with backoff, using a fresh signed link if the old one has expired, and nothing is
|
|
149
|
+
left at the destination. A body that matches its `Content-Length` but not the stored size, and
|
|
150
|
+
a storage 400/401/403, are retried only once. When every attempt comes back short, `IncompleteDownloadError`
|
|
151
|
+
(a subclass of `APIConnectionError`) reports `received_bytes` and `expected_bytes`.
|
|
152
|
+
Downloading by job ID reads the job first to learn the expected size. If that read has no output yet
|
|
153
|
+
(a `payment_required` job, or one that finished just after the read), the job is read again once the
|
|
154
|
+
signed link exists, so every download is checked against the stored size.
|
|
155
|
+
|
|
156
|
+
## Filler removal
|
|
157
|
+
|
|
158
|
+
`audio.remove_fillers()` (`POST /v1/audio/remove-fillers`, model `zilapi/filler-1.0`) finds filled
|
|
159
|
+
pauses (um, uh, er) in speech and cuts them out. It costs $0.020 per audio minute of input, billed by
|
|
160
|
+
the millisecond with a 1-second minimum; inputs can be up to 30 minutes. Pass a ready `file` or an https
|
|
161
|
+
`input_url`. Works best on single-speaker speech; with overlapping speakers short words can
|
|
162
|
+
occasionally be cut.
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from zilapi import ZilAPI
|
|
166
|
+
|
|
167
|
+
with ZilAPI() as client:
|
|
168
|
+
job = client.audio.remove_fillers(input_url="https://example.com/episode-142.wav")
|
|
169
|
+
job = client.jobs.wait(job)
|
|
170
|
+
if job.succeeded and job.fillers is not None:
|
|
171
|
+
report = job.fillers # Also job.result.fillers.
|
|
172
|
+
print(report.count, "fillers,", report.removed_seconds, "s removed")
|
|
173
|
+
for segment in report.segments or []:
|
|
174
|
+
print(f"{segment.start_s:.2f}-{segment.end_s:.2f} s ({segment.confidence})")
|
|
175
|
+
client.jobs.download(job, "episode-no-fillers.mp3", name="audio")
|
|
176
|
+
client.jobs.download(job, "episode-fillers.json", name="fillers") # The same report as JSON.
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
`timestamps_only=True` skips the edited audio: the job has only the `fillers` output, and
|
|
180
|
+
`output_duration_seconds` is `None`. The price is the same. In `jobs.list()` the report is a summary
|
|
181
|
+
(`segments` is `None`); `jobs.retrieve()` returns every segment.
|
|
182
|
+
|
|
183
|
+
## Background removal
|
|
184
|
+
|
|
185
|
+
`images.remove_background()` (`POST /v1/image/remove-background`, model `zilapi/bgr-1.0`, $0.01 per
|
|
186
|
+
image) cuts the subject out of a PNG, JPEG or WebP photo. Pass exactly one input:
|
|
187
|
+
|
|
188
|
+
- a local image as the first argument: a path, `bytes` or a seekable binary stream (give `filename`
|
|
189
|
+
for bytes and unnamed streams). Up to 20 MiB it is sent in one multipart request, read into memory
|
|
190
|
+
once so a retry resends the same bytes; a larger image is streamed with `files.create()` and passed
|
|
191
|
+
by file ID, so memory stays bounded;
|
|
192
|
+
- `file=`: an uploaded file's ID or `File` (from `files.create()`);
|
|
193
|
+
- `input_url=`: an https URL the API downloads.
|
|
194
|
+
|
|
195
|
+
The API is asynchronous: it creates a job, which you poll or receive by webhook. By default
|
|
196
|
+
`remove_background()` waits for it, polling every second for the first minute and every five seconds
|
|
197
|
+
after that, up to `timeout=600` seconds (`WaitTimeoutError` carries the last job). It returns a
|
|
198
|
+
`BackgroundRemoval` (`AsyncBackgroundRemoval` on the async client) with two outputs:
|
|
199
|
+
|
|
200
|
+
- `image`: the cut-out, a PNG with an alpha channel (RGBA, straight alpha), the same size as the
|
|
201
|
+
input after its EXIF orientation is applied;
|
|
202
|
+
- `mask`: the alpha matte, an 8-bit greyscale PNG of the same size.
|
|
203
|
+
|
|
204
|
+
```python
|
|
205
|
+
from zilapi import ZilAPI
|
|
206
|
+
|
|
207
|
+
with ZilAPI() as client:
|
|
208
|
+
result = client.images.remove_background("photo.jpg", end_user="user-42")
|
|
209
|
+
if result.succeeded:
|
|
210
|
+
result.save("photo-cutout.png") # The cut-out (a directory uses photo-cutout.png).
|
|
211
|
+
result.save_mask("photo-mask.png") # The alpha matte.
|
|
212
|
+
png_bytes = result.read() # Or keep it in memory; read_mask() for the mask.
|
|
213
|
+
print(result.job.receipt.unit_price_display) # "$0.01 / image"
|
|
214
|
+
else:
|
|
215
|
+
print(result.error.code if result.error else result.status) # For example invalid_image.
|
|
216
|
+
|
|
217
|
+
# From a URL, without waiting: take a webhook or wait later.
|
|
218
|
+
pending = client.images.remove_background(
|
|
219
|
+
input_url="https://example.com/shoe.webp",
|
|
220
|
+
webhook_url="https://example.com/hooks/zilapi",
|
|
221
|
+
wait=False,
|
|
222
|
+
)
|
|
223
|
+
done = pending.wait(timeout=120)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Webhook deliveries are signed. Verify each one before trusting it (signing secret, HMAC-SHA256 over
|
|
227
|
+
the raw body, constant-time comparison, timestamp window) as described in
|
|
228
|
+
https://zilapi.com/docs/webhooks/#verify.
|
|
229
|
+
|
|
230
|
+
The async client is the same with `await`:
|
|
231
|
+
`result = await client.images.remove_background("photo.jpg")`, then `await result.save(...)`.
|
|
232
|
+
|
|
233
|
+
Failed and canceled jobs are returned, not raised (check `succeeded` and `error`); `save()`, `read()`
|
|
234
|
+
and their mask versions raise `JobFailedError` (with `code`, `message` and `job`) when the job did not
|
|
235
|
+
succeed. A `payment_required` job (bill after) can be saved too: the output endpoint pays it from
|
|
236
|
+
your credit first, or answers `402 payment_required` (`result.job.payment` says what is due). A job
|
|
237
|
+
that already finished is returned by `wait()` without polling. The server validates images (format, file size, pixel limits); the SDK does not duplicate
|
|
238
|
+
those limits. A rejected image usually comes back as a failed job (`invalid_image`,
|
|
239
|
+
`image_too_large`), but some rejections are request errors raised at creation, as `APIStatusError`
|
|
240
|
+
subclasses: for example `FileTooLargeError` (413) for an oversized upload, or
|
|
241
|
+
`UnprocessableEntityError` (422 `invalid_image`) for an audio `file=`. The API's `options` field is
|
|
242
|
+
not exposed: background removal takes no options. Outputs are kept for 7
|
|
243
|
+
days; `jobs.download(job, path, name="mask")` works on any image job too.
|
|
244
|
+
|
|
245
|
+
### Coming from remove.bg
|
|
246
|
+
|
|
247
|
+
remove.bg answers a request with the image itself; ZilAPI runs a job, and the SDK's wait hides that.
|
|
248
|
+
A drop-in helper for scripts that called remove.bg:
|
|
249
|
+
|
|
250
|
+
```python
|
|
251
|
+
from zilapi import ZilAPI
|
|
252
|
+
|
|
253
|
+
client = ZilAPI() # Reads ZILAPI_KEY; reuse one client for many images.
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
def remove_background(src: str, dst: str) -> None:
|
|
257
|
+
"""Like remove.bg's image_file -> PNG: raises JobFailedError if the image was rejected."""
|
|
258
|
+
client.images.remove_background(src).save(dst, overwrite=True)
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
remove_background("photo.jpg", "photo-no-bg.png")
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
| remove.bg (`POST /v1.0/removebg`) | ZilAPI |
|
|
265
|
+
|---|---|
|
|
266
|
+
| `image_file` | first argument (path, bytes or stream) |
|
|
267
|
+
| `image_url` | `input_url=` |
|
|
268
|
+
| `X-Api-Key` header | `ZILAPI_KEY` / `ZilAPI(api_key=...)` |
|
|
269
|
+
| response body (PNG) | `result.save(path)` / `result.read()` |
|
|
270
|
+
| `type=`, `size=`, `bg_color=`, `format=` | not supported: the output is always a full-size PNG cut-out plus its mask |
|
|
271
|
+
|
|
272
|
+
## Errors and retries
|
|
273
|
+
|
|
274
|
+
```python
|
|
275
|
+
from zilapi import APIStatusError, FileRejectedError, RateLimitError, WaitTimeoutError, ZilAPI
|
|
276
|
+
|
|
277
|
+
with ZilAPI() as client:
|
|
278
|
+
try:
|
|
279
|
+
file = client.files.create("recording.wav")
|
|
280
|
+
except FileRejectedError as exc:
|
|
281
|
+
print(exc.code, exc.message)
|
|
282
|
+
except WaitTimeoutError as exc:
|
|
283
|
+
print(exc.last.id, exc.last.status) # Resume polling later.
|
|
284
|
+
except RateLimitError as exc:
|
|
285
|
+
print(exc.code, exc.retry_after)
|
|
286
|
+
except APIStatusError as exc:
|
|
287
|
+
print(exc.status, exc.code, exc.detail, exc.request_id)
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
All SDK error classes derive from `ZilAPIError`. HTTP errors expose `.headers` and
|
|
291
|
+
`.body`, including rate-limit headers. Transport failures raise `APIConnectionError`
|
|
292
|
+
or `APITimeoutError`. Failed storage PUTs raise `UploadError` with `.part_number`
|
|
293
|
+
and `.status_code`. A success status whose body is not a JSON object (for example an
|
|
294
|
+
HTML page from a proxy), an unexpected empty body, or a body missing required fields
|
|
295
|
+
raises `APIResponseValidationError`, a subclass of `APIStatusError`.
|
|
296
|
+
|
|
297
|
+
Storage uploads and downloads use their own connection pool (signed URLs never carry
|
|
298
|
+
your API key) and, like API calls, honour `HTTPS_PROXY`, `HTTP_PROXY`, `NO_PROXY`,
|
|
299
|
+
`SSL_CERT_FILE` and `SSL_CERT_DIR`. A custom `http_client` applies to API calls only.
|
|
300
|
+
|
|
301
|
+
The API request layer retries GETs and POSTs carrying an idempotency key, with two
|
|
302
|
+
retries by default. It retries transport failures, 429, and all 5xx responses.
|
|
303
|
+
DELETE and POST without a key are never retried. Backoff starts at 0.5 seconds,
|
|
304
|
+
doubles up to 8 seconds, and uses jitter between half and all of that delay.
|
|
305
|
+
`Retry-After` seconds or HTTP dates override backoff; values over 60 seconds fail
|
|
306
|
+
immediately. Storage PUTs allow three retries. Downloads use the client's retry limit.
|
|
307
|
+
|
|
308
|
+
Creating POSTs generate an idempotency key once and reuse it on retries (a local image is read
|
|
309
|
+
once, so a retry resends the same bytes). Supply `idempotency_key` to `files.create()`,
|
|
310
|
+
`audio.denoise()` or `images.remove_background()` when coordinating your
|
|
311
|
+
own retries; use the same key only with the same body. The server retains replay
|
|
312
|
+
records for 24 hours. File completion uses `<key>:complete`, so file-create keys
|
|
313
|
+
are limited to 246 characters to keep both keys within the API's 255-character limit.
|
|
314
|
+
Job keys may use all 255 characters.
|
|
315
|
+
|
|
316
|
+
## Configuration
|
|
317
|
+
|
|
318
|
+
```python
|
|
319
|
+
import httpx
|
|
320
|
+
from zilapi import ZilAPI
|
|
321
|
+
|
|
322
|
+
with ZilAPI(
|
|
323
|
+
# api_key defaults to ZILAPI_KEY (then the older ZILAPI_API_KEY); base_url to ZILAPI_BASE_URL,
|
|
324
|
+
# then https://api.zilapi.com.
|
|
325
|
+
base_url="https://api.zilapi.com",
|
|
326
|
+
timeout=httpx.Timeout(60.0, connect=10.0),
|
|
327
|
+
max_retries=2,
|
|
328
|
+
default_headers={"X-Application": "audio-worker"},
|
|
329
|
+
) as client:
|
|
330
|
+
credits = client.with_options(max_retries=0, timeout=5.0).credits.retrieve()
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
Explicit configuration overrides environment variables. A float timeout uses that
|
|
334
|
+
value for HTTPX timeouts and `min(10, timeout)` for connecting. `with_options()`
|
|
335
|
+
returns a shallow view sharing connections; keep its original client open. Closing
|
|
336
|
+
a view does not close the original. If you supply `http_client`, you retain ownership
|
|
337
|
+
and must close it yourself. The SDK owns and closes its separate storage client.
|
|
338
|
+
|
|
339
|
+
Storage requests never receive API authorization or custom API headers. SDK DEBUG
|
|
340
|
+
logs on the `zilapi` logger include request status, request ID, attempt, and retry
|
|
341
|
+
delay; storage URLs are reduced to scheme and host. The SDK also adds a filter to
|
|
342
|
+
the `httpx` logger that redacts signed query strings, and storage error bodies are
|
|
343
|
+
never kept in exceptions. Lower-level wire tracing (e.g. `httpcore` at TRACE) is not
|
|
344
|
+
filtered, so avoid it when handling credentials or signed URLs.
|
|
345
|
+
|
|
346
|
+
## Pagination
|
|
347
|
+
|
|
348
|
+
```python
|
|
349
|
+
with ZilAPI() as client:
|
|
350
|
+
for job in client.jobs.list(limit=100, status="succeeded"):
|
|
351
|
+
print(job.id)
|
|
352
|
+
page = client.jobs.list_page(limit=20)
|
|
353
|
+
if page.next_cursor is not None:
|
|
354
|
+
next_page = client.jobs.list_page(limit=20, cursor=page.next_cursor)
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
`limit` is page size (1-100), not a total result limit. Iteration loads pages lazily.
|
|
358
|
+
The async equivalent is `async for job in client.jobs.list(...)` inside an
|
|
359
|
+
`async with AsyncZilAPI()` block; `list_page()` is awaited. Both support a `model` filter.
|
|
360
|
+
|
|
361
|
+
## Development
|
|
362
|
+
|
|
363
|
+
```sh
|
|
364
|
+
pip install -e ".[dev]"
|
|
365
|
+
pytest -q
|
|
366
|
+
ruff check .
|
|
367
|
+
ruff format --check .
|
|
368
|
+
mypy --strict src tests
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
Default tests use mocked HTTP; they never require credentials or make network calls.
|
|
372
|
+
Development versions are pinned to the supplied tooling, with Python 3.9 compatible
|
|
373
|
+
pytest/pytest-asyncio fallbacks and mypy installed only on Python 3.10+.
|
|
374
|
+
|
|
375
|
+
Live tests generate a two-second WAV, upload it, denoise it, and download the MP3:
|
|
376
|
+
|
|
377
|
+
```sh
|
|
378
|
+
export ZILAPI_KEY="<your test key>"
|
|
379
|
+
pytest -m live
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
They also remove the background of a generated 16x16 PNG. They skip without a key, and refuse
|
|
383
|
+
non-test keys unless `ZILAPI_ALLOW_LIVE=1`. The host defaults to `https://api.zilapi.com`
|
|
384
|
+
(`ZILAPI_BASE_URL` overrides it). CI runs mocked tests on Python 3.9-3.13; lint and typing
|
|
385
|
+
run on 3.12.
|
|
386
|
+
|
|
387
|
+
License: MIT. See [LICENSE](LICENSE).
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
zilapi/__init__.py,sha256=PGKDqSNDqKG3FkxsdtGS9vBgcc9jK3L4j23iKj8UlZY,2189
|
|
2
|
+
zilapi/_base.py,sha256=ED1QyGZguJu62Jk-RUv9lvRvncVjWl3uHmzSEY5qNGo,10286
|
|
3
|
+
zilapi/_client.py,sha256=8V6z_MWJaWPDol9b8pVdSP5hWgu81j4nXFjmonPpU8U,11016
|
|
4
|
+
zilapi/_downloads.py,sha256=AposqE8_pZjun-PmSgZGQwmkxeGDBZTjMHRDevc39i0,11042
|
|
5
|
+
zilapi/_uploads.py,sha256=BETXPB3uZiR2XGGuqndgYV_ih6S0lmiheqy5qRTJUm4,7437
|
|
6
|
+
zilapi/_version.py,sha256=LNXf6M_lZErGYISSiJYaqKkwbXz_6Wl3EiD9MApOXek,58
|
|
7
|
+
zilapi/errors.py,sha256=ynixca3X9W7Ii53z3uWbFyxdt5wosHoOhYF89G256cs,5079
|
|
8
|
+
zilapi/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
zilapi/types.py,sha256=EMjw78ZuF7QAxwUF0LHMW5On7-QtZEHgwUf1wgXLQA8,16399
|
|
10
|
+
zilapi/resources/__init__.py,sha256=hgdLlnkNC5_Re_6ctWLSjE8TGK94Akbn0hcsK4YuBU4,93
|
|
11
|
+
zilapi/resources/audio.py,sha256=4NvD3HXYvbXMCCzFKIKwcA8W0RWzWm7uTq2Ti8EeXfw,4137
|
|
12
|
+
zilapi/resources/credits.py,sha256=6FuOTvirbpmYb4Fhata5ySxqZajy8-6RDzSr5STvKUU,791
|
|
13
|
+
zilapi/resources/files.py,sha256=QbFuIjzG8oLCvX8VK_eMJLW44bkwEeAcZi7-VZgq3U0,11766
|
|
14
|
+
zilapi/resources/images.py,sha256=d0_vS3b4g1iBf1gcANRGo7PKT9DZlyMClS-Byw7tzDg,16020
|
|
15
|
+
zilapi/resources/jobs.py,sha256=k01xJxFtTc8WoQWrS52IAUPp0zx-jDUsevbIGOYNvcs,11108
|
|
16
|
+
zilapi/resources/models.py,sha256=IxijjWb9vpeuRcfXRnS9ZtqQHMnnQ1s8IcfkzhAua6g,1243
|
|
17
|
+
zilapi-0.5.0.dist-info/METADATA,sha256=-hB_9Nt7bccC-p5DHqhtb0oea3UQwqTP-Akf5sRPZh8,18258
|
|
18
|
+
zilapi-0.5.0.dist-info/WHEEL,sha256=W3fkpkm7-wf9vBI5Z-7s0eWkeM-spu78I8Neb98DeEg,87
|
|
19
|
+
zilapi-0.5.0.dist-info/licenses/LICENSE,sha256=Ml7DoApoNyJ9jXbG0l1xHdBS4tR-bAXSUlZixFe5DAY,1066
|
|
20
|
+
zilapi-0.5.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 InverseAI
|
|
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.
|