runapi-kie 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,88 @@
1
+ Metadata-Version: 2.5
2
+ Name: runapi-kie
3
+ Version: 0.1.0
4
+ Summary: RunAPI KIE SDK for image and video upscaling workflows in JavaScript, Python, Ruby, Go, Java, and PHP
5
+ Project-URL: Homepage, https://runapi.ai/models/kie
6
+ Project-URL: Documentation, https://runapi.ai/docs/resources/sdks
7
+ Project-URL: Source, https://github.com/runapi-ai/kie-sdk
8
+ Project-URL: Issues, https://github.com/runapi-ai/kie-sdk/issues
9
+ Project-URL: Changelog, https://github.com/runapi-ai/kie-sdk/blob/main/CHANGELOG.md
10
+ Project-URL: Release Notes, https://github.com/runapi-ai/kie-sdk/releases/tag/python%2Fv0.1.0
11
+ Author-email: RunAPI <contact@runapi.ai>
12
+ License-Expression: Apache-2.0
13
+ Keywords: api,golang,gradle,image-upscaling,java,kie,kie-api,maven,python,ruby,runapi,runapi-ai,sdk,typescript,upscaling,video-upscaling
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Requires-Python: >=3.10
21
+ Requires-Dist: runapi-core~=0.12.0
22
+ Description-Content-Type: text/markdown
23
+
24
+ # KIE Python SDK for RunAPI
25
+
26
+ The KIE Python SDK is the language-specific package for KIE on RunAPI. Use this package for image and video upscaling workflows when your application needs request bodies, task status lookup, and consistent RunAPI errors in Python.
27
+
28
+ This README is the Python package guide inside the public `kie-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/kie; for API reference, use https://runapi.ai/docs/api/kie/upscale-image; for SDK docs, use https://runapi.ai/docs/resources/sdks.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ pip install runapi-kie
34
+ ```
35
+
36
+ ## Quick start
37
+
38
+ ```python
39
+ from runapi.kie import KieClient
40
+
41
+ client = KieClient() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
42
+
43
+ task = client.upscale_image.create(
44
+ model="kie-upscale-image",
45
+ source_image_url="https://cdn.runapi.ai/public/samples/upscale.jpg",
46
+ upscale_factor="4",
47
+ )
48
+ status = client.upscale_image.get(task.id)
49
+
50
+ video = client.upscale_video.create(
51
+ model="kie-upscale-video",
52
+ source_video_url="https://cdn.runapi.ai/public/samples/video-lowres.mp4",
53
+ resolution="2K",
54
+ )
55
+ ```
56
+
57
+ Use `create` to submit a task and return quickly, `get` to fetch the latest task state, and `run` when a script should create and poll until completion:
58
+
59
+ ```python
60
+ result = client.upscale_image.run(
61
+ model="kie-upscale-image",
62
+ source_image_url="https://cdn.runapi.ai/public/samples/upscale.jpg",
63
+ upscale_factor="4",
64
+ )
65
+ print(result.images[0].url)
66
+ ```
67
+
68
+ In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
69
+
70
+ RunAPI-generated file URLs are temporary. Download and store generated images, videos, audio, or other files in your own durable storage within 7 days; do not treat returned URLs as long-term assets.
71
+
72
+ ## Language notes
73
+
74
+ Pass parameters as keyword arguments and catch the `runapi.kie` error classes when building upscaling jobs or scripts. The available resources are `upscale_image` and `upscale_video`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
75
+
76
+ ## Links
77
+
78
+ - Model page: https://runapi.ai/models/kie
79
+ - SDK docs: https://runapi.ai/docs/resources/sdks
80
+ - Product docs: https://runapi.ai/docs/api/kie/upscale-image
81
+ - Pricing and rate limits: https://runapi.ai/models/kie/upscale-image
82
+ - Provider comparison: https://runapi.ai/providers/kie
83
+ - Full catalog: https://runapi.ai/models
84
+ - Repository: https://github.com/runapi-ai/kie-sdk
85
+
86
+ ## License
87
+
88
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,65 @@
1
+ # KIE Python SDK for RunAPI
2
+
3
+ The KIE Python SDK is the language-specific package for KIE on RunAPI. Use this package for image and video upscaling workflows when your application needs request bodies, task status lookup, and consistent RunAPI errors in Python.
4
+
5
+ This README is the Python package guide inside the public `kie-sdk` repository. For the repository overview, start at `../README.md`; for model details, use https://runapi.ai/models/kie; for API reference, use https://runapi.ai/docs/api/kie/upscale-image; for SDK docs, use https://runapi.ai/docs/resources/sdks.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install runapi-kie
11
+ ```
12
+
13
+ ## Quick start
14
+
15
+ ```python
16
+ from runapi.kie import KieClient
17
+
18
+ client = KieClient() # reads RUNAPI_API_KEY, or pass api_key="sk-..."
19
+
20
+ task = client.upscale_image.create(
21
+ model="kie-upscale-image",
22
+ source_image_url="https://cdn.runapi.ai/public/samples/upscale.jpg",
23
+ upscale_factor="4",
24
+ )
25
+ status = client.upscale_image.get(task.id)
26
+
27
+ video = client.upscale_video.create(
28
+ model="kie-upscale-video",
29
+ source_video_url="https://cdn.runapi.ai/public/samples/video-lowres.mp4",
30
+ resolution="2K",
31
+ )
32
+ ```
33
+
34
+ Use `create` to submit a task and return quickly, `get` to fetch the latest task state, and `run` when a script should create and poll until completion:
35
+
36
+ ```python
37
+ result = client.upscale_image.run(
38
+ model="kie-upscale-image",
39
+ source_image_url="https://cdn.runapi.ai/public/samples/upscale.jpg",
40
+ upscale_factor="4",
41
+ )
42
+ print(result.images[0].url)
43
+ ```
44
+
45
+ In web request handlers, prefer `create` plus webhook or later `get` polling so a worker is not held open.
46
+
47
+ RunAPI-generated file URLs are temporary. Download and store generated images, videos, audio, or other files in your own durable storage within 7 days; do not treat returned URLs as long-term assets.
48
+
49
+ ## Language notes
50
+
51
+ Pass parameters as keyword arguments and catch the `runapi.kie` error classes when building upscaling jobs or scripts. The available resources are `upscale_image` and `upscale_video`. Keep `RUNAPI_API_KEY` in the environment or your secret manager; never commit API keys or callback secrets.
52
+
53
+ ## Links
54
+
55
+ - Model page: https://runapi.ai/models/kie
56
+ - SDK docs: https://runapi.ai/docs/resources/sdks
57
+ - Product docs: https://runapi.ai/docs/api/kie/upscale-image
58
+ - Pricing and rate limits: https://runapi.ai/models/kie/upscale-image
59
+ - Provider comparison: https://runapi.ai/providers/kie
60
+ - Full catalog: https://runapi.ai/models
61
+ - Repository: https://github.com/runapi-ai/kie-sdk
62
+
63
+ ## License
64
+
65
+ Licensed under the Apache License, Version 2.0.
@@ -0,0 +1,42 @@
1
+ [build-system]
2
+ requires = ["hatchling"]
3
+ build-backend = "hatchling.build"
4
+
5
+ [project]
6
+ name = "runapi-kie"
7
+ version = "0.1.0"
8
+ description = "RunAPI KIE SDK for image and video upscaling workflows in JavaScript, Python, Ruby, Go, Java, and PHP"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ classifiers = [
12
+ "Programming Language :: Python :: 3",
13
+ "Programming Language :: Python :: 3.10",
14
+ "Programming Language :: Python :: 3.11",
15
+ "Programming Language :: Python :: 3.12",
16
+ "Programming Language :: Python :: 3.13",
17
+ "Programming Language :: Python :: 3.14",
18
+ ]
19
+ license = "Apache-2.0"
20
+ authors = [{ name = "RunAPI", email = "contact@runapi.ai" }]
21
+ keywords = ["runapi", "runapi-ai", "kie", "api", "sdk", "typescript", "python", "ruby", "golang", "java", "maven", "gradle", "upscaling", "image-upscaling", "video-upscaling", "kie-api"]
22
+ dependencies = ["runapi-core~=0.12.0"]
23
+
24
+ [project.urls]
25
+ Homepage = "https://runapi.ai/models/kie"
26
+ Documentation = "https://runapi.ai/docs/resources/sdks"
27
+ Source = "https://github.com/runapi-ai/kie-sdk"
28
+ Issues = "https://github.com/runapi-ai/kie-sdk/issues"
29
+ Changelog = "https://github.com/runapi-ai/kie-sdk/blob/main/CHANGELOG.md"
30
+ "Release Notes" = "https://github.com/runapi-ai/kie-sdk/releases/tag/python%2Fv0.1.0"
31
+
32
+ [tool.hatch.build.targets.wheel]
33
+ packages = ["src/runapi"]
34
+
35
+ [tool.uv]
36
+ package = true
37
+
38
+ [dependency-groups]
39
+ dev = ["pytest>=8"]
40
+
41
+ [tool.runapi]
42
+ slug = "kie"
@@ -0,0 +1,24 @@
1
+ """Kie client for RunAPI."""
2
+
3
+ from runapi.core import (
4
+ AuthenticationError,
5
+ InsufficientCreditsError,
6
+ NotFoundError,
7
+ RateLimitError,
8
+ TaskFailedError,
9
+ TaskTimeoutError,
10
+ ValidationError,
11
+ )
12
+
13
+ from .client import KieClient
14
+
15
+ __all__ = [
16
+ "KieClient",
17
+ "AuthenticationError",
18
+ "RateLimitError",
19
+ "InsufficientCreditsError",
20
+ "NotFoundError",
21
+ "ValidationError",
22
+ "TaskFailedError",
23
+ "TaskTimeoutError",
24
+ ]
@@ -0,0 +1,30 @@
1
+ """Kie client."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Optional
6
+
7
+ from runapi.core import ProviderClient
8
+
9
+ from .resources.upscale_image import UpscaleImage
10
+ from .resources.upscale_video import UpscaleVideo
11
+
12
+
13
+ class KieClient(ProviderClient):
14
+ """Kie image and video upscale client.
15
+
16
+ Example::
17
+
18
+ client = KieClient(api_key="sk-...")
19
+ result = client.upscale_image.run(
20
+ model="kie-upscale-image",
21
+ source_image_url="https://runapi.ai/in.jpg",
22
+ upscale_factor="4",
23
+ )
24
+ """
25
+
26
+ def __init__(self, api_key: Optional[str] = None, **options: Any) -> None:
27
+ super().__init__(api_key, **options)
28
+ http = self._http
29
+ self.upscale_image = UpscaleImage(http)
30
+ self.upscale_video = UpscaleVideo(http)
File without changes
@@ -0,0 +1,4 @@
1
+ from .upscale_image import UpscaleImage
2
+ from .upscale_video import UpscaleVideo
3
+
4
+ __all__ = ["UpscaleImage", "UpscaleVideo"]
@@ -0,0 +1,56 @@
1
+ """Kie upscale-image resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Optional
6
+
7
+ from runapi.core import Resource, RequestOptions
8
+
9
+ from ..types import (
10
+ CompletedUpscaleImageResponse,
11
+ UpscaleImageResponse,
12
+ )
13
+
14
+
15
+ class UpscaleImage(Resource):
16
+ """Upscale images with Kie."""
17
+
18
+ ENDPOINT = "/api/v1/kie/upscale_image"
19
+
20
+ RESPONSE_CLASS = UpscaleImageResponse
21
+ COMPLETED_RESPONSE_CLASS = CompletedUpscaleImageResponse
22
+
23
+ def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
24
+ """Upscale an image and poll until it completes.
25
+
26
+ Args:
27
+ **params: image upscale parameters (model, ...).
28
+
29
+ Returns:
30
+ The completed (narrowed) image upscale response.
31
+ """
32
+ task = self.create(options=options, **params)
33
+ return self._poll_until_complete(lambda: self.get(task.id, options=options))
34
+
35
+ def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
36
+ """Create an image upscale task and return immediately with an id.
37
+
38
+ Args:
39
+ **params: image upscale parameters (model, ...).
40
+
41
+ Returns:
42
+ The task creation result with an id.
43
+ """
44
+ compacted = self._compact_params(params)
45
+ return self._request("post", self.ENDPOINT, body=compacted, options=options)
46
+
47
+ def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
48
+ """Fetch the current status of an image upscale task.
49
+
50
+ Args:
51
+ id: The task id returned by ``create``.
52
+
53
+ Returns:
54
+ The current task status.
55
+ """
56
+ return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
@@ -0,0 +1,56 @@
1
+ """Kie upscale-video resource."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from typing import Any, Optional
6
+
7
+ from runapi.core import Resource, RequestOptions
8
+
9
+ from ..types import (
10
+ CompletedUpscaleVideoResponse,
11
+ UpscaleVideoResponse,
12
+ )
13
+
14
+
15
+ class UpscaleVideo(Resource):
16
+ """Upscale videos with Kie."""
17
+
18
+ ENDPOINT = "/api/v1/kie/upscale_video"
19
+
20
+ RESPONSE_CLASS = UpscaleVideoResponse
21
+ COMPLETED_RESPONSE_CLASS = CompletedUpscaleVideoResponse
22
+
23
+ def run(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
24
+ """Upscale a video and poll until it completes.
25
+
26
+ Args:
27
+ **params: video upscale parameters (model, ...).
28
+
29
+ Returns:
30
+ The completed (narrowed) video upscale response.
31
+ """
32
+ task = self.create(options=options, **params)
33
+ return self._poll_until_complete(lambda: self.get(task.id, options=options))
34
+
35
+ def create(self, options: Optional[RequestOptions] = None, **params: Any) -> Any:
36
+ """Create a video upscale task and return immediately with an id.
37
+
38
+ Args:
39
+ **params: video upscale parameters (model, ...).
40
+
41
+ Returns:
42
+ The task creation result with an id.
43
+ """
44
+ compacted = self._compact_params(params)
45
+ return self._request("post", self.ENDPOINT, body=compacted, options=options)
46
+
47
+ def get(self, id: str, options: Optional[RequestOptions] = None) -> Any:
48
+ """Fetch the current status of a video upscale task.
49
+
50
+ Args:
51
+ id: The task id returned by ``create``.
52
+
53
+ Returns:
54
+ The current task status.
55
+ """
56
+ return self._request("get", f"{self.ENDPOINT}/{id}", options=options)
@@ -0,0 +1,43 @@
1
+ """Kie response models."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from runapi.core import BaseModel, TaskResponse, optional, required
6
+
7
+
8
+ class Image(BaseModel):
9
+ url = optional(str)
10
+
11
+
12
+ class Video(BaseModel):
13
+ url = optional(str)
14
+
15
+
16
+ class UpscaleImageResponse(TaskResponse):
17
+ """Kie image upscale task status response."""
18
+
19
+ id = required(str)
20
+ status = optional(str, enum=lambda: TaskResponse.Status.ALL)
21
+ images = optional([lambda: Image])
22
+ error = optional(str)
23
+
24
+
25
+ class UpscaleVideoResponse(TaskResponse):
26
+ """Kie video upscale task status response."""
27
+
28
+ id = required(str)
29
+ status = optional(str, enum=lambda: TaskResponse.Status.ALL)
30
+ videos = optional([lambda: Video])
31
+ error = optional(str)
32
+
33
+
34
+ class CompletedUpscaleImageResponse(UpscaleImageResponse):
35
+ """Narrowed response from ``run()`` once polling observes completion."""
36
+
37
+ images = required([lambda: Image])
38
+
39
+
40
+ class CompletedUpscaleVideoResponse(UpscaleVideoResponse):
41
+ """Narrowed response from ``run()`` once polling observes completion."""
42
+
43
+ videos = required([lambda: Video])
@@ -0,0 +1,151 @@
1
+ import pytest
2
+
3
+ from runapi.core import config
4
+ from runapi.core.errors import AuthenticationError
5
+ from runapi.kie import KieClient
6
+ from runapi.kie.resources.upscale_image import UpscaleImage
7
+ from runapi.kie.resources.upscale_video import UpscaleVideo
8
+ from runapi.kie.types import (
9
+ CompletedUpscaleImageResponse,
10
+ CompletedUpscaleVideoResponse,
11
+ UpscaleImageResponse,
12
+ UpscaleVideoResponse,
13
+ )
14
+
15
+
16
+ class FakeHttp:
17
+ def __init__(self, *responses):
18
+ self._responses = list(responses)
19
+ self.calls = []
20
+
21
+ def request(self, method, path, body=None, options=None):
22
+ self.calls.append((method, path, body))
23
+ if self._responses:
24
+ return self._responses.pop(0)
25
+ return {"id": "task_1", "status": "pending"}
26
+
27
+
28
+ @pytest.fixture(autouse=True)
29
+ def reset_config(monkeypatch):
30
+ monkeypatch.delenv("RUNAPI_API_KEY", raising=False)
31
+ monkeypatch.setattr(config, "api_key", None)
32
+ yield
33
+
34
+
35
+ # --- auth -----------------------------------------------------------------
36
+
37
+
38
+ def test_accepts_api_key_parameter():
39
+ assert isinstance(KieClient(api_key="k", http_client=FakeHttp()), KieClient)
40
+
41
+
42
+ def test_falls_back_to_global(monkeypatch):
43
+ monkeypatch.setattr(config, "api_key", "global-key")
44
+ assert isinstance(KieClient(http_client=FakeHttp()), KieClient)
45
+
46
+
47
+ def test_falls_back_to_env(monkeypatch):
48
+ monkeypatch.setenv("RUNAPI_API_KEY", "env-key")
49
+ assert isinstance(KieClient(http_client=FakeHttp()), KieClient)
50
+
51
+
52
+ def test_raises_without_api_key():
53
+ with pytest.raises(AuthenticationError, match="API key is required"):
54
+ KieClient()
55
+
56
+
57
+ # --- injection / accessors ------------------------------------------------
58
+
59
+
60
+ def test_uses_injected_http_client():
61
+ fake = FakeHttp()
62
+ client = KieClient(api_key="k", http_client=fake)
63
+ assert client.upscale_image._http is fake
64
+ assert client.upscale_video._http is fake
65
+
66
+
67
+ def test_exposes_resource_accessors():
68
+ client = KieClient(api_key="k", http_client=FakeHttp())
69
+ assert isinstance(client.upscale_image, UpscaleImage)
70
+ assert isinstance(client.upscale_video, UpscaleVideo)
71
+
72
+
73
+ # --- request shapes -------------------------------------------------------
74
+
75
+
76
+ def test_create_posts_compacted_body():
77
+ fake = FakeHttp({"id": "t1", "status": "pending"})
78
+ client = KieClient(api_key="k", http_client=fake)
79
+ result = client.upscale_image.create(
80
+ model="kie-upscale-image",
81
+ source_image_url="https://x/y.jpg",
82
+ upscale_factor="4",
83
+ note=None,
84
+ )
85
+ assert fake.calls == [
86
+ (
87
+ "post",
88
+ "/api/v1/kie/upscale_image",
89
+ {"model": "kie-upscale-image", "source_image_url": "https://x/y.jpg", "upscale_factor": "4"},
90
+ )]
91
+ assert isinstance(result, UpscaleImageResponse)
92
+
93
+
94
+ def test_get_fetches_by_id():
95
+ fake = FakeHttp({"id": "t1", "status": "processing"})
96
+ client = KieClient(api_key="k", http_client=fake)
97
+ client.upscale_image.get("t1")
98
+ assert fake.calls == [("get", "/api/v1/kie/upscale_image/t1", None)]
99
+
100
+
101
+ def test_video_create_posts_compacted_body():
102
+ fake = FakeHttp({"id": "t1", "status": "pending"})
103
+ client = KieClient(api_key="k", http_client=fake)
104
+ result = client.upscale_video.create(
105
+ model="kie-upscale-video",
106
+ source_video_url="https://x/y.mp4",
107
+ resolution="2K",
108
+ )
109
+ assert fake.calls == [
110
+ (
111
+ "post",
112
+ "/api/v1/kie/upscale_video",
113
+ {"model": "kie-upscale-video", "source_video_url": "https://x/y.mp4", "resolution": "2K"},
114
+ )]
115
+ assert isinstance(result, UpscaleVideoResponse)
116
+
117
+
118
+ def test_run_narrows_completed_image_type():
119
+ fake = FakeHttp(
120
+ {"id": "t1", "status": "pending"},
121
+ {"id": "t1", "status": "completed", "usage": {"cost": 0.05}, "images": [{"url": "https://x/y.png"}]},
122
+ )
123
+ client = KieClient(api_key="k", http_client=fake)
124
+ result = client.upscale_image.run(
125
+ model="kie-upscale-image", source_image_url="https://x/y.jpg", upscale_factor="4"
126
+ )
127
+ assert isinstance(result, CompletedUpscaleImageResponse)
128
+ assert result.images[0].url == "https://x/y.png"
129
+
130
+
131
+ def test_run_narrows_completed_video_type():
132
+ fake = FakeHttp(
133
+ {"id": "t1", "status": "pending"},
134
+ {"id": "t1", "status": "completed", "usage": {"cost": 0.05}, "videos": [{"url": "https://x/y.mp4"}]},
135
+ )
136
+ client = KieClient(api_key="k", http_client=fake)
137
+ result = client.upscale_video.run(
138
+ model="kie-upscale-video", source_video_url="https://x/y.mp4", resolution="2K"
139
+ )
140
+ assert isinstance(result, CompletedUpscaleVideoResponse)
141
+ assert result.videos[0].url == "https://x/y.mp4"
142
+
143
+
144
+ def test_video_allows_default_resolution():
145
+ fake = FakeHttp({"id": "t1", "status": "pending"})
146
+ client = KieClient(api_key="k", http_client=fake)
147
+ client.upscale_video.create(
148
+ model="kie-upscale-video", source_video_url="https://x/y.mp4"
149
+ )
150
+ _, _, body = fake.calls[0]
151
+ assert "resolution" not in body