useknockout 0.6.0__tar.gz → 0.7.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.
- {useknockout-0.6.0 → useknockout-0.7.0}/PKG-INFO +1 -1
- {useknockout-0.6.0 → useknockout-0.7.0}/pyproject.toml +1 -1
- useknockout-0.7.0/src/useknockout/_version.py +1 -0
- {useknockout-0.6.0 → useknockout-0.7.0}/src/useknockout/async_client.py +54 -3
- {useknockout-0.6.0 → useknockout-0.7.0}/src/useknockout/client.py +59 -3
- useknockout-0.6.0/src/useknockout/_version.py +0 -1
- {useknockout-0.6.0 → useknockout-0.7.0}/.gitignore +0 -0
- {useknockout-0.6.0 → useknockout-0.7.0}/LICENSE +0 -0
- {useknockout-0.6.0 → useknockout-0.7.0}/README.md +0 -0
- {useknockout-0.6.0 → useknockout-0.7.0}/SERVICES.md +0 -0
- {useknockout-0.6.0 → useknockout-0.7.0}/TECHSTACK.md +0 -0
- {useknockout-0.6.0 → useknockout-0.7.0}/src/useknockout/__init__.py +0 -0
- {useknockout-0.6.0 → useknockout-0.7.0}/src/useknockout/_helpers.py +0 -0
- {useknockout-0.6.0 → useknockout-0.7.0}/src/useknockout/errors.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: useknockout
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.0
|
|
4
4
|
Summary: Python SDK for useknockout — state-of-the-art background removal API.
|
|
5
5
|
Project-URL: Homepage, https://useknockout.com
|
|
6
6
|
Project-URL: Documentation, https://github.com/useknockout/python
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.7.0"
|
|
@@ -88,11 +88,13 @@ class AsyncKnockout:
|
|
|
88
88
|
data=None,
|
|
89
89
|
json=None,
|
|
90
90
|
params=None,
|
|
91
|
+
timeout=None,
|
|
91
92
|
) -> Any:
|
|
92
93
|
try:
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
kwargs = {"files": files, "data": data, "json": json, "params": params}
|
|
95
|
+
if timeout is not None:
|
|
96
|
+
kwargs["timeout"] = timeout
|
|
97
|
+
r = await self._http.request(method, path, **kwargs)
|
|
96
98
|
except httpx.RequestError as e:
|
|
97
99
|
raise KnockoutError(f"network error: {e}", code="unknown") from e
|
|
98
100
|
if r.status_code >= 400:
|
|
@@ -315,6 +317,55 @@ class AsyncKnockout:
|
|
|
315
317
|
timeout=45.0 + len(files) * 20.0,
|
|
316
318
|
)
|
|
317
319
|
|
|
320
|
+
async def video_remove(
|
|
321
|
+
self,
|
|
322
|
+
file: FileInput,
|
|
323
|
+
*,
|
|
324
|
+
format: str = "prores4444",
|
|
325
|
+
bg_color: Optional[str] = None,
|
|
326
|
+
smoothing: int = 30,
|
|
327
|
+
) -> Dict[str, Any]:
|
|
328
|
+
"""POST /video/remove — async video background removal. Returns the job
|
|
329
|
+
dict; poll with get_job() or use video_remove_and_wait(). Paid tiers,
|
|
330
|
+
$0.05/output-second, 30s/200MB caps."""
|
|
331
|
+
return await self._request_json(
|
|
332
|
+
"POST",
|
|
333
|
+
"/video/remove",
|
|
334
|
+
files=_multipart_files(file),
|
|
335
|
+
data=_form({"format": format, "bg_color": bg_color, "smoothing": smoothing}),
|
|
336
|
+
timeout=300.0,
|
|
337
|
+
)
|
|
338
|
+
|
|
339
|
+
async def get_job(self, job_id: str) -> Dict[str, Any]:
|
|
340
|
+
"""GET /jobs/{job_id} — poll a video job once."""
|
|
341
|
+
return await self._request_json("GET", f"/jobs/{job_id}")
|
|
342
|
+
|
|
343
|
+
async def video_remove_and_wait(
|
|
344
|
+
self,
|
|
345
|
+
file: FileInput,
|
|
346
|
+
*,
|
|
347
|
+
format: str = "prores4444",
|
|
348
|
+
bg_color: Optional[str] = None,
|
|
349
|
+
smoothing: int = 30,
|
|
350
|
+
poll_interval: float = 5.0,
|
|
351
|
+
timeout: float = 900.0,
|
|
352
|
+
) -> Dict[str, Any]:
|
|
353
|
+
"""Submit a video and await completion. Returns the final job dict;
|
|
354
|
+
raises KnockoutError on job failure or wait timeout."""
|
|
355
|
+
import asyncio as _asyncio
|
|
356
|
+
import time as _time
|
|
357
|
+
|
|
358
|
+
job = await self.video_remove(file, format=format, bg_color=bg_color, smoothing=smoothing)
|
|
359
|
+
deadline = _time.monotonic() + timeout
|
|
360
|
+
while job.get("status") in ("queued", "processing"):
|
|
361
|
+
if _time.monotonic() > deadline:
|
|
362
|
+
raise KnockoutError(f"video job {job.get('job_id')} still running after {timeout}s", code="timeout")
|
|
363
|
+
await _asyncio.sleep(poll_interval)
|
|
364
|
+
job = await self.get_job(job["job_id"])
|
|
365
|
+
if job.get("status") == "error":
|
|
366
|
+
raise KnockoutError(f"video job {job.get('job_id')} failed: {job.get('error')}", code="job_error")
|
|
367
|
+
return job
|
|
368
|
+
|
|
318
369
|
async def compare(self, file: FileInput, *, format: str = "png") -> bytes:
|
|
319
370
|
return await self._request_bytes(
|
|
320
371
|
"POST",
|
|
@@ -98,11 +98,13 @@ class Knockout:
|
|
|
98
98
|
data=None,
|
|
99
99
|
json=None,
|
|
100
100
|
params=None,
|
|
101
|
+
timeout=None,
|
|
101
102
|
) -> Any:
|
|
102
103
|
try:
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
104
|
+
kwargs = {"files": files, "data": data, "json": json, "params": params}
|
|
105
|
+
if timeout is not None:
|
|
106
|
+
kwargs["timeout"] = timeout
|
|
107
|
+
r = self._http.request(method, path, **kwargs)
|
|
106
108
|
except httpx.RequestError as e:
|
|
107
109
|
raise KnockoutError(f"network error: {e}", code="unknown") from e
|
|
108
110
|
if r.status_code >= 400:
|
|
@@ -357,6 +359,60 @@ class Knockout:
|
|
|
357
359
|
timeout=45.0 + len(files) * 20.0,
|
|
358
360
|
)
|
|
359
361
|
|
|
362
|
+
def video_remove(
|
|
363
|
+
self,
|
|
364
|
+
file: FileInput,
|
|
365
|
+
*,
|
|
366
|
+
format: str = "prores4444",
|
|
367
|
+
bg_color: Optional[str] = None,
|
|
368
|
+
smoothing: int = 30,
|
|
369
|
+
) -> Dict[str, Any]:
|
|
370
|
+
"""POST /video/remove — async video background removal. Returns the job
|
|
371
|
+
dict immediately ({job_id, status, seconds, ...}); poll with get_job()
|
|
372
|
+
or use video_remove_and_wait().
|
|
373
|
+
|
|
374
|
+
format: 'prores4444' (MOV, real 10-bit alpha), 'webm' (VP9 alpha), or
|
|
375
|
+
'mp4' (H.264 — requires bg_color). Paid tiers only, $0.05 per output
|
|
376
|
+
second, billed on success. Caps: 30s clip, 30fps, 200MB.
|
|
377
|
+
"""
|
|
378
|
+
return self._request_json(
|
|
379
|
+
"POST",
|
|
380
|
+
"/video/remove",
|
|
381
|
+
files=_multipart_files(file),
|
|
382
|
+
data=_form({"format": format, "bg_color": bg_color, "smoothing": smoothing}),
|
|
383
|
+
timeout=300.0, # uploads up to 200MB + server-side probe
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
def get_job(self, job_id: str) -> Dict[str, Any]:
|
|
387
|
+
"""GET /jobs/{job_id} — poll a video job once."""
|
|
388
|
+
return self._request_json("GET", f"/jobs/{job_id}")
|
|
389
|
+
|
|
390
|
+
def video_remove_and_wait(
|
|
391
|
+
self,
|
|
392
|
+
file: FileInput,
|
|
393
|
+
*,
|
|
394
|
+
format: str = "prores4444",
|
|
395
|
+
bg_color: Optional[str] = None,
|
|
396
|
+
smoothing: int = 30,
|
|
397
|
+
poll_interval: float = 5.0,
|
|
398
|
+
timeout: float = 900.0,
|
|
399
|
+
) -> Dict[str, Any]:
|
|
400
|
+
"""Submit a video and block until it finishes. Returns the final job
|
|
401
|
+
dict (status 'done', result_url set). Raises KnockoutError on job
|
|
402
|
+
failure or wait timeout."""
|
|
403
|
+
import time as _time
|
|
404
|
+
|
|
405
|
+
job = self.video_remove(file, format=format, bg_color=bg_color, smoothing=smoothing)
|
|
406
|
+
deadline = _time.monotonic() + timeout
|
|
407
|
+
while job.get("status") in ("queued", "processing"):
|
|
408
|
+
if _time.monotonic() > deadline:
|
|
409
|
+
raise KnockoutError(f"video job {job.get('job_id')} still running after {timeout}s", code="timeout")
|
|
410
|
+
_time.sleep(poll_interval)
|
|
411
|
+
job = self.get_job(job["job_id"])
|
|
412
|
+
if job.get("status") == "error":
|
|
413
|
+
raise KnockoutError(f"video job {job.get('job_id')} failed: {job.get('error')}", code="job_error")
|
|
414
|
+
return job
|
|
415
|
+
|
|
360
416
|
def compare(self, file: FileInput, *, format: str = "png") -> bytes:
|
|
361
417
|
"""POST /compare — side-by-side before/after image."""
|
|
362
418
|
return self._request_bytes(
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.6.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|