wavespeed 0.0.1__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.
wavespeed/__init__.py ADDED
@@ -0,0 +1,18 @@
1
+ """
2
+ Wavespeed AI Python Client
3
+
4
+ A Python client for interacting with the Wavespeed AI API.
5
+ """
6
+
7
+ __version__ = "0.1.0"
8
+
9
+ from .client import Wavespeed
10
+ from .schemas.prediction import Prediction, PredictionUrls, PredictionResponse
11
+
12
+ __all__ = [
13
+ "Wavespeed",
14
+ "Prediction",
15
+ "PredictionUrls",
16
+ "PredictionResponse",
17
+ "__version__",
18
+ ]
wavespeed/client.py ADDED
@@ -0,0 +1,150 @@
1
+ import os
2
+ import httpx
3
+ from typing import Dict, Any
4
+ from urllib.parse import urljoin
5
+
6
+ from wavespeed.schemas.prediction import Prediction
7
+
8
+
9
+ class Wavespeed:
10
+ """
11
+ A client for interacting with the Wavespeed AI API.
12
+ """
13
+
14
+ BASE_URL = "https://api.wavespeed.ai/api/v2/"
15
+
16
+ def __init__(self, api_key: str):
17
+ """
18
+ Initialize the Wavespeed client.
19
+
20
+ Args:
21
+ api_key: Your Wavespeed API key
22
+ """
23
+ self.api_key = api_key
24
+ if not api_key:
25
+ api_key = os.environ.get("WAVESPEED_API_KEY", '')
26
+ if not api_key:
27
+ raise ValueError("API key is required.")
28
+ self.headers = {
29
+ "Content-Type": "application/json",
30
+ "Authorization": f"Bearer {api_key}"
31
+ }
32
+ self.async_client = httpx.AsyncClient(headers=self.headers)
33
+ self.client = httpx.Client(headers=self.headers)
34
+ self.poll_interval = float(os.environ.get("WAVESPEED_POLL_INTERVAL", 1)) # seconds
35
+ self.timeout = int(os.environ.get("WAVESPEED_TIMEOUT", 60)) # seconds
36
+
37
+ async def async_run(
38
+ self,
39
+ modelId: str,
40
+ input: Dict[str, Any],
41
+ **kwargs
42
+ ) -> Prediction:
43
+ """
44
+ Generate an image using the Wavespeed AI API.
45
+
46
+ Args:
47
+ modelId: The ID of the model to use
48
+ input: Input parameters for the model
49
+ **kwargs: Additional parameters to pass to the API
50
+
51
+ Returns:
52
+ The API response as a dictionary
53
+ """
54
+ url = urljoin(self.BASE_URL, modelId)
55
+
56
+ payload = input
57
+
58
+ # Reset client if it's closed
59
+ if self.async_client.is_closed:
60
+ self.async_client = httpx.AsyncClient()
61
+
62
+ response = await self.async_client.post(
63
+ url,
64
+ headers=self.headers,
65
+ json=payload,
66
+ timeout=self.timeout
67
+ )
68
+
69
+ # Raise an exception for HTTP errors
70
+ response.raise_for_status()
71
+ data = response.json()
72
+ prediction = Prediction(**data['data'])
73
+ prediction._client = self
74
+ return await prediction.async_wait()
75
+
76
+ def run(
77
+ self,
78
+ modelId: str,
79
+ input: Dict[str, Any],
80
+ **kwargs
81
+ ) -> Prediction:
82
+ """
83
+ Generate an image using the Wavespeed AI API.
84
+
85
+ Args:
86
+ modelId: The ID of the model to use
87
+ input: Input parameters for the model
88
+ **kwargs: Additional parameters to pass to the API
89
+
90
+ Returns:
91
+ The API response as a dictionary
92
+ """
93
+ url = urljoin(self.BASE_URL, modelId)
94
+
95
+ payload = input
96
+
97
+ response = self.client.post(
98
+ url,
99
+ headers=self.headers,
100
+ json=payload,
101
+ timeout=self.timeout
102
+ )
103
+
104
+ # Raise an exception for HTTP errors
105
+ response.raise_for_status()
106
+ data = response.json()
107
+ prediction = Prediction(**data['data'])
108
+ prediction._client = self
109
+ return prediction.wait()
110
+
111
+ async def async_create(self, modelId: str, input: Dict[str, Any], **kwargs) -> Prediction:
112
+ url = urljoin(self.BASE_URL, modelId)
113
+ payload = input
114
+ response = await self.async_client.post(
115
+ url,
116
+ headers=self.headers,
117
+ json=payload,
118
+ timeout=self.timeout
119
+ )
120
+ # Raise an exception for HTTP errors
121
+ response.raise_for_status()
122
+ data = response.json()
123
+ prediction = Prediction(**data['data'])
124
+ prediction._client = self
125
+ return prediction
126
+
127
+ def create(self, modelId: str, input: Dict[str, Any], **kwargs) -> Prediction:
128
+ url = urljoin(self.BASE_URL, modelId)
129
+ payload = input
130
+ response = self.client.post(
131
+ url,
132
+ headers=self.headers,
133
+ json=payload,
134
+ timeout=self.timeout
135
+ )
136
+ # Raise an exception for HTTP errors
137
+ response.raise_for_status()
138
+ data = response.json()
139
+ prediction = Prediction(**data['data'])
140
+ prediction._client = self
141
+ return prediction
142
+
143
+ async def close(self):
144
+ """Close the httpx client session."""
145
+ self.client.close()
146
+ await self.async_client.aclose()
147
+
148
+ def __str__(self) -> str:
149
+ """String representation of the client."""
150
+ return f"WavespeedClient()"
@@ -0,0 +1,270 @@
1
+ Metadata-Version: 2.4
2
+ Name: wavespeed
3
+ Version: 0.0.1
4
+ Summary: Python client for Wavespeed
5
+ Author: Wavespeed, Inc.
6
+ License: MIT License
7
+
8
+ Copyright (c) 2025 Wavespeed AI
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+ Project-URL: homepage, https://wavespeed.ai
28
+ Project-URL: repository, https://github.com/wavespeed-ai/wavespeed-python
29
+ Requires-Python: >=3.8
30
+ Description-Content-Type: text/markdown
31
+ License-File: LICENSE
32
+ Requires-Dist: httpx<1,>=0.21.0
33
+ Requires-Dist: packaging
34
+ Requires-Dist: pydantic>1.10.7
35
+ Requires-Dist: typing_extensions>=4.5.0
36
+ Dynamic: license-file
37
+
38
+ # Wavespeed Python Client
39
+
40
+ A Python client for interacting with the Wavespeed AI API.
41
+
42
+ ## Installation
43
+
44
+ ```bash
45
+ pip install wavespeed
46
+ ```
47
+
48
+ ## Usage
49
+
50
+ ### Synchronous Image Generation
51
+
52
+ ```python
53
+ from wavespeed import Wavespeed
54
+
55
+ # Initialize the client with your API key (or set WAVESPEED_API_KEY environment variable)
56
+ client = Wavespeed(api_key="YOUR_API_KEY")
57
+
58
+ # Generate an image and wait for the result
59
+ prediction = client.run(
60
+ modelId="wavespeed-ai/flux-dev",
61
+ input={
62
+ "prompt": "A futuristic cityscape with flying cars and neon lights",
63
+ "size": "1024*1024",
64
+ "num_inference_steps": 28,
65
+ "guidance_scale": 5.0,
66
+ "num_images": 1,
67
+ "seed": -1,
68
+ "enable_safety_checker": True
69
+ }
70
+ )
71
+
72
+ # Print the generated image URLs
73
+ for i, img_url in enumerate(prediction.outputs):
74
+ print(f"Image {i+1}: {img_url}")
75
+ ```
76
+
77
+ ### Asynchronous Image Generation
78
+
79
+ ```python
80
+ import asyncio
81
+ from wavespeed import Wavespeed
82
+
83
+ async def generate_image():
84
+ # Initialize the client with your API key (or set WAVESPEED_API_KEY environment variable)
85
+ client = Wavespeed(api_key="YOUR_API_KEY")
86
+
87
+ try:
88
+ # Generate an image and wait for the result
89
+ prediction = await client.async_run(
90
+ modelId="wavespeed-ai/flux-dev",
91
+ input={
92
+ "prompt": "A futuristic cityscape with flying cars and neon lights",
93
+ "size": "1024*1024",
94
+ "num_inference_steps": 28,
95
+ "guidance_scale": 5.0,
96
+ "num_images": 1,
97
+ "seed": -1,
98
+ "enable_safety_checker": True
99
+ }
100
+ )
101
+
102
+ # Print the generated image URLs
103
+ for i, img_url in enumerate(prediction.outputs):
104
+ print(f"Image {i+1}: {img_url}")
105
+ finally:
106
+ # Always close the client when done
107
+ await client.close()
108
+
109
+ # Run the async function
110
+ asyncio.run(generate_image())
111
+ ```
112
+
113
+ ### Non-blocking Image Generation
114
+
115
+ You can also create a prediction without waiting for it to complete:
116
+
117
+ ```python
118
+ from wavespeed import Wavespeed
119
+
120
+ # Initialize the client with your API key (or set WAVESPEED_API_KEY environment variable)
121
+ client = Wavespeed(api_key="YOUR_API_KEY")
122
+
123
+ # Create a prediction without waiting
124
+ prediction = client.create(
125
+ modelId="wavespeed-ai/flux-dev",
126
+ input={
127
+ "prompt": "A futuristic cityscape with flying cars and neon lights",
128
+ "size": "1024*1024",
129
+ "num_inference_steps": 28,
130
+ "guidance_scale": 5.0,
131
+ "num_images": 1,
132
+ "seed": -1,
133
+ "enable_safety_checker": True
134
+ }
135
+ )
136
+
137
+ print(f"Prediction created with ID: {prediction.id}")
138
+ print(f"Initial status: {prediction.status}")
139
+
140
+ # Later, you can wait for the prediction to complete
141
+ result = prediction.wait()
142
+ print(f"Final status: {result.status}")
143
+
144
+ # Print the generated image URLs
145
+ for i, img_url in enumerate(result.outputs):
146
+ print(f"Image {i+1}: {img_url}")
147
+ ```
148
+
149
+ ## Command Line Examples
150
+
151
+ The package includes several example scripts that you can use to generate images:
152
+
153
+ ### Basic Image Generation
154
+
155
+ ```bash
156
+ # Set your API key as an environment variable
157
+ export WAVESPEED_API_KEY="your_api_key_here"
158
+
159
+ # Run the example script
160
+ python examples/generate_image.py --prompt "A futuristic cityscape with flying cars and neon lights"
161
+ ```
162
+
163
+ ### Asynchronous Image Generation
164
+
165
+ ```bash
166
+ # Run the async example script
167
+ python examples/async_generate_image.py --prompt "A futuristic cityscape with flying cars and neon lights"
168
+ ```
169
+
170
+ ### Non-blocking Image Generation
171
+
172
+ ```bash
173
+ # Create a prediction and poll for status
174
+ python examples/create_generate_image.py --prompt "A futuristic cityscape with flying cars and neon lights"
175
+ ```
176
+
177
+ ### Command Line Options
178
+
179
+ ```
180
+ --prompt TEXT Text description of the desired image (required)
181
+ --strength FLOAT How much to transform the input image (0.0 to 1.0)
182
+ --size WIDTHxHEIGHT Image dimensions (default: 1024*1024)
183
+ --steps INT Number of inference steps (default: 28)
184
+ --guidance FLOAT How closely to follow the prompt (default: 5.0)
185
+ --num-images INT Number of images to generate (default: 1)
186
+ --seed INT Random seed (-1 for random)
187
+ --safety Enable content safety filtering
188
+ ```
189
+
190
+ ## API Reference
191
+
192
+ ### Wavespeed Client
193
+
194
+ ```python
195
+ Wavespeed(api_key)
196
+ ```
197
+
198
+ #### Parameters:
199
+
200
+ - `api_key` (str): Your Wavespeed API key
201
+
202
+ ### Methods
203
+
204
+ #### run
205
+
206
+ ```python
207
+ run(modelId, input, **kwargs) -> Prediction
208
+ ```
209
+
210
+ Generate an image and wait for the result.
211
+
212
+ #### async_run
213
+
214
+ ```python
215
+ async_run(modelId, input, **kwargs) -> Prediction
216
+ ```
217
+
218
+ Asynchronously generate an image and wait for the result.
219
+
220
+ #### create
221
+
222
+ ```python
223
+ create(modelId, input, **kwargs) -> Prediction
224
+ ```
225
+
226
+ Create a prediction without waiting for it to complete.
227
+
228
+ #### async_create
229
+
230
+ ```python
231
+ async_create(modelId, input, **kwargs) -> Prediction
232
+ ```
233
+
234
+ Asynchronously create a prediction without waiting for it to complete.
235
+
236
+ ### Prediction Model
237
+
238
+ The `Prediction` object contains information about an image generation job:
239
+
240
+ ```python
241
+ prediction.id # Unique ID of the prediction
242
+ prediction.model # Model ID used for the prediction
243
+ prediction.status # Status of the prediction (processing, completed, failed)
244
+ prediction.outputs # List of output image URLs
245
+ prediction.input # Input parameters used for the prediction
246
+ prediction.created_at # Creation timestamp
247
+ prediction.error # Error message (if any)
248
+ prediction.executionTime # Time taken to execute the prediction in milliseconds
249
+ ```
250
+
251
+ #### Methods
252
+
253
+ ```python
254
+ prediction.wait() -> Prediction # Wait for the prediction to complete
255
+ prediction.reload() -> Prediction # Reload the prediction status
256
+
257
+ # Async versions
258
+ await prediction.async_wait() -> Prediction
259
+ await prediction.async_reload() -> Prediction
260
+ ```
261
+
262
+ ## Environment Variables
263
+
264
+ - `WAVESPEED_API_KEY`: Your Wavespeed API key
265
+ - `WAVESPEED_POLL_INTERVAL`: Interval in seconds for polling prediction status (default: 1)
266
+ - `WAVESPEED_TIMEOUT`: Timeout in seconds for API requests (default: 60)
267
+
268
+ ## License
269
+
270
+ MIT
@@ -0,0 +1,7 @@
1
+ wavespeed/__init__.py,sha256=nKKSL3zBnSilkCnBbEM5QnV57mbBYo1L0zo3dy6boF4,344
2
+ wavespeed/client.py,sha256=wOXgXewQSZEERt5CyLkAFM7KGX5SLi3vydykU7KssV4,4502
3
+ wavespeed-0.0.1.dist-info/licenses/LICENSE,sha256=Ped14Wt87nPIhDPJxj5b8ZoHVHnktCBmJsSJ_Fov6KM,1068
4
+ wavespeed-0.0.1.dist-info/METADATA,sha256=obdqF-AN4QSJ-EpTCyI61gLgwYZ3Oj5Oo5GluvoCINo,7761
5
+ wavespeed-0.0.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
6
+ wavespeed-0.0.1.dist-info/top_level.txt,sha256=4S7lS5Vrdmel6Lg7UE5GK85WTaW_b8V_RxT59dAbV5I,10
7
+ wavespeed-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (78.1.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Wavespeed AI
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 @@
1
+ wavespeed