runqy-python 0.2.0__tar.gz → 0.2.1__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: runqy-python
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Python SDK for runqy - write distributed task handlers with simple decorators
5
5
  Author: Publikey
6
6
  Project-URL: Documentation, https://docs.runqy.com
@@ -118,7 +118,7 @@ from runqy_python import RunqyClient
118
118
  client = RunqyClient("http://localhost:3000", api_key="your-api-key")
119
119
 
120
120
  # Enqueue a task
121
- task = client.enqueue("inference_default", {"input": "hello"})
121
+ task = client.enqueue("inference.default", {"input": "hello"})
122
122
  print(f"Task ID: {task.task_id}")
123
123
 
124
124
  # Check result
@@ -132,7 +132,7 @@ Or use the convenience function:
132
132
  from runqy_python import enqueue
133
133
 
134
134
  task = enqueue(
135
- "inference_default",
135
+ "inference.default",
136
136
  {"input": "hello"},
137
137
  server_url="http://localhost:3000",
138
138
  api_key="your-api-key"
@@ -147,7 +147,7 @@ task = enqueue(
147
147
  - `timeout`: Default request timeout in seconds
148
148
 
149
149
  **client.enqueue(queue, payload, timeout=300)**
150
- - `queue`: Queue name (e.g., `"inference_default"`)
150
+ - `queue`: Queue name (e.g., `"inference.default"`)
151
151
  - `payload`: Task payload as a dict
152
152
  - `timeout`: Task execution timeout in seconds
153
153
  - Returns: `TaskInfo` with `task_id`, `queue`, `state`
@@ -95,7 +95,7 @@ from runqy_python import RunqyClient
95
95
  client = RunqyClient("http://localhost:3000", api_key="your-api-key")
96
96
 
97
97
  # Enqueue a task
98
- task = client.enqueue("inference_default", {"input": "hello"})
98
+ task = client.enqueue("inference.default", {"input": "hello"})
99
99
  print(f"Task ID: {task.task_id}")
100
100
 
101
101
  # Check result
@@ -109,7 +109,7 @@ Or use the convenience function:
109
109
  from runqy_python import enqueue
110
110
 
111
111
  task = enqueue(
112
- "inference_default",
112
+ "inference.default",
113
113
  {"input": "hello"},
114
114
  server_url="http://localhost:3000",
115
115
  api_key="your-api-key"
@@ -124,7 +124,7 @@ task = enqueue(
124
124
  - `timeout`: Default request timeout in seconds
125
125
 
126
126
  **client.enqueue(queue, payload, timeout=300)**
127
- - `queue`: Queue name (e.g., `"inference_default"`)
127
+ - `queue`: Queue name (e.g., `"inference.default"`)
128
128
  - `payload`: Task payload as a dict
129
129
  - `timeout`: Task execution timeout in seconds
130
130
  - Returns: `TaskInfo` with `task_id`, `queue`, `state`
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "runqy-python"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  description = "Python SDK for runqy - write distributed task handlers with simple decorators"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.8"
@@ -8,10 +8,12 @@ from .runner import run, run_once
8
8
  from .client import (
9
9
  RunqyClient,
10
10
  TaskInfo,
11
+ BatchResult,
11
12
  RunqyError,
12
13
  AuthenticationError,
13
14
  TaskNotFoundError,
14
15
  enqueue,
16
+ enqueue_batch,
15
17
  )
16
18
 
17
19
  __all__ = [
@@ -23,10 +25,12 @@ __all__ = [
23
25
  # Client
24
26
  "RunqyClient",
25
27
  "TaskInfo",
28
+ "BatchResult",
26
29
  "RunqyError",
27
30
  "AuthenticationError",
28
31
  "TaskNotFoundError",
29
32
  "enqueue",
33
+ "enqueue_batch",
30
34
  ]
31
35
 
32
36
  __version__ = "0.2.0"
@@ -42,6 +42,22 @@ class TaskInfo:
42
42
  payload: Optional[Dict[str, Any]] = None
43
43
 
44
44
 
45
+ @dataclass
46
+ class BatchResult:
47
+ """Result of a batch enqueue operation.
48
+
49
+ Attributes:
50
+ enqueued: Number of successfully enqueued tasks
51
+ failed: Number of failed tasks
52
+ task_ids: List of task IDs for successful tasks
53
+ errors: List of error messages for failed tasks
54
+ """
55
+ enqueued: int
56
+ failed: int
57
+ task_ids: list
58
+ errors: list
59
+
60
+
45
61
  class RunqyClient:
46
62
  """Client for interacting with runqy server.
47
63
 
@@ -49,7 +65,7 @@ class RunqyClient:
49
65
  client = RunqyClient("http://localhost:3000", api_key="your-api-key")
50
66
 
51
67
  # Enqueue a task
52
- task = client.enqueue("inference_default", {"input": "hello"})
68
+ task = client.enqueue("inference.default", {"input": "hello"})
53
69
  print(f"Task ID: {task.task_id}")
54
70
 
55
71
  # Check result
@@ -128,7 +144,7 @@ class RunqyClient:
128
144
  """Enqueue a task to a queue.
129
145
 
130
146
  Args:
131
- queue: Queue name (e.g., "inference_default")
147
+ queue: Queue name (e.g., "inference.default")
132
148
  payload: Task payload data
133
149
  timeout: Task execution timeout in seconds (default: 300)
134
150
 
@@ -140,7 +156,7 @@ class RunqyClient:
140
156
  RunqyError: For other errors
141
157
 
142
158
  Example:
143
- task = client.enqueue("inference_default", {"input": "hello"})
159
+ task = client.enqueue("inference.default", {"input": "hello"})
144
160
  print(f"Enqueued task: {task.task_id}")
145
161
  """
146
162
  data = {
@@ -159,6 +175,58 @@ class RunqyClient:
159
175
  payload=payload,
160
176
  )
161
177
 
178
+ def enqueue_batch(
179
+ self,
180
+ queue: str,
181
+ payloads: list,
182
+ timeout: int = 300
183
+ ) -> BatchResult:
184
+ """Enqueue multiple tasks in a single request.
185
+
186
+ Uses the batch endpoint for high-throughput job submission.
187
+ This is significantly faster than calling enqueue() multiple times.
188
+
189
+ Args:
190
+ queue: Queue name (e.g., "inference.default")
191
+ payloads: List of task payload dictionaries
192
+ timeout: Task execution timeout in seconds (default: 300)
193
+
194
+ Returns:
195
+ BatchResult with counts and task IDs
196
+
197
+ Raises:
198
+ AuthenticationError: If API key is invalid
199
+ RunqyError: For other errors
200
+
201
+ Example:
202
+ result = client.enqueue_batch("inference.default", [
203
+ {"input": "hello"},
204
+ {"input": "world"},
205
+ {"input": "foo"},
206
+ ])
207
+ print(f"Enqueued: {result.enqueued}, Task IDs: {result.task_ids}")
208
+ """
209
+ # Build jobs array with proper structure
210
+ jobs = [
211
+ {"timeout": timeout, "data": payload}
212
+ for payload in payloads
213
+ ]
214
+
215
+ data = {
216
+ "queue": queue,
217
+ "timeout": timeout,
218
+ "jobs": jobs,
219
+ }
220
+
221
+ response = self._request("POST", "/queue/add-batch", data)
222
+
223
+ return BatchResult(
224
+ enqueued=response.get("enqueued", 0),
225
+ failed=response.get("failed", 0),
226
+ task_ids=response.get("task_ids", []),
227
+ errors=response.get("errors", []),
228
+ )
229
+
162
230
  def get_task(self, task_id: str) -> TaskInfo:
163
231
  """Get task status and result.
164
232
 
@@ -217,7 +285,7 @@ def enqueue(
217
285
  """Quick enqueue without creating a client instance.
218
286
 
219
287
  Args:
220
- queue: Queue name (e.g., "inference_default")
288
+ queue: Queue name (e.g., "inference.default")
221
289
  payload: Task payload data
222
290
  server_url: Base URL of the runqy server
223
291
  api_key: API key for authentication
@@ -230,7 +298,7 @@ def enqueue(
230
298
  from runqy_python import enqueue
231
299
 
232
300
  task = enqueue(
233
- "inference_default",
301
+ "inference.default",
234
302
  {"input": "hello"},
235
303
  server_url="http://localhost:3000",
236
304
  api_key="your-api-key"
@@ -238,3 +306,36 @@ def enqueue(
238
306
  print(f"Task ID: {task.task_id}")
239
307
  """
240
308
  return RunqyClient(server_url, api_key).enqueue(queue, payload, timeout)
309
+
310
+
311
+ def enqueue_batch(
312
+ queue: str,
313
+ payloads: list,
314
+ server_url: str,
315
+ api_key: str,
316
+ timeout: int = 300
317
+ ) -> BatchResult:
318
+ """Quick batch enqueue without creating a client instance.
319
+
320
+ Args:
321
+ queue: Queue name (e.g., "inference.default")
322
+ payloads: List of task payload dictionaries
323
+ server_url: Base URL of the runqy server
324
+ api_key: API key for authentication
325
+ timeout: Task execution timeout in seconds (default: 300)
326
+
327
+ Returns:
328
+ BatchResult with counts and task IDs
329
+
330
+ Example:
331
+ from runqy_python import enqueue_batch
332
+
333
+ result = enqueue_batch(
334
+ "inference.default",
335
+ [{"input": "hello"}, {"input": "world"}],
336
+ server_url="http://localhost:3000",
337
+ api_key="your-api-key"
338
+ )
339
+ print(f"Enqueued {result.enqueued} tasks")
340
+ """
341
+ return RunqyClient(server_url, api_key).enqueue_batch(queue, payloads, timeout)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: runqy-python
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Python SDK for runqy - write distributed task handlers with simple decorators
5
5
  Author: Publikey
6
6
  Project-URL: Documentation, https://docs.runqy.com
@@ -118,7 +118,7 @@ from runqy_python import RunqyClient
118
118
  client = RunqyClient("http://localhost:3000", api_key="your-api-key")
119
119
 
120
120
  # Enqueue a task
121
- task = client.enqueue("inference_default", {"input": "hello"})
121
+ task = client.enqueue("inference.default", {"input": "hello"})
122
122
  print(f"Task ID: {task.task_id}")
123
123
 
124
124
  # Check result
@@ -132,7 +132,7 @@ Or use the convenience function:
132
132
  from runqy_python import enqueue
133
133
 
134
134
  task = enqueue(
135
- "inference_default",
135
+ "inference.default",
136
136
  {"input": "hello"},
137
137
  server_url="http://localhost:3000",
138
138
  api_key="your-api-key"
@@ -147,7 +147,7 @@ task = enqueue(
147
147
  - `timeout`: Default request timeout in seconds
148
148
 
149
149
  **client.enqueue(queue, payload, timeout=300)**
150
- - `queue`: Queue name (e.g., `"inference_default"`)
150
+ - `queue`: Queue name (e.g., `"inference.default"`)
151
151
  - `payload`: Task payload as a dict
152
152
  - `timeout`: Task execution timeout in seconds
153
153
  - Returns: `TaskInfo` with `task_id`, `queue`, `state`
File without changes
File without changes