yarlis-studio-sdk 0.1.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.
@@ -0,0 +1,468 @@
1
+ Metadata-Version: 2.4
2
+ Name: yarlis-studio-sdk
3
+ Version: 0.1.1
4
+ Summary: Yarlis Studio SDK - Execute workflows programmatically
5
+ Home-page: https://github.com/yarlis/ystudio
6
+ Author: Yarlis AI
7
+ Author-email: Yarlis AI <support@mybotbox.com>
8
+ License: Apache-2.0
9
+ Project-URL: Homepage, https://mybotbox.com
10
+ Project-URL: Documentation, https://docs.mybotbox.com
11
+ Project-URL: Repository, https://github.com/yarlis/ystudio
12
+ Project-URL: Bug Reports, https://github.com/yarlis/ystudio/issues
13
+ Keywords: yarlis,ystudio,ai,workflow,sdk,api,automation
14
+ Classifier: Development Status :: 4 - Beta
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: Apache Software License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.8
20
+ Classifier: Programming Language :: Python :: 3.9
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
25
+ Classifier: Topic :: Internet :: WWW/HTTP :: HTTP Servers
26
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
27
+ Requires-Python: >=3.8
28
+ Description-Content-Type: text/markdown
29
+ Requires-Dist: requests>=2.25.0
30
+ Requires-Dist: typing-extensions>=4.0.0; python_version < "3.10"
31
+ Provides-Extra: dev
32
+ Requires-Dist: pytest>=6.0.0; extra == "dev"
33
+ Requires-Dist: pytest-asyncio>=0.18.0; extra == "dev"
34
+ Requires-Dist: black>=22.0.0; extra == "dev"
35
+ Requires-Dist: flake8>=4.0.0; extra == "dev"
36
+ Requires-Dist: mypy>=0.910; extra == "dev"
37
+ Requires-Dist: isort>=5.0.0; extra == "dev"
38
+ Requires-Dist: types-requests>=2.25.0; extra == "dev"
39
+ Dynamic: author
40
+ Dynamic: home-page
41
+ Dynamic: requires-python
42
+
43
+ # MyBotBox Python SDK
44
+
45
+ The official Python SDK for [MyBotBox](https://mybotbox.com), allowing you to execute workflows programmatically from your Python applications.
46
+
47
+ ## Installation
48
+
49
+ ```bash
50
+ pip install @yarlisai/studio-sdk
51
+ ```
52
+
53
+ ## Quick Start
54
+
55
+ ```python
56
+ import os
57
+ from mybotbox import MyBotBoxClient
58
+
59
+ # Initialize the client
60
+ client = MyBotBoxClient(
61
+ api_key=os.getenv("MBB_API_KEY", "your-api-key-here"),
62
+ base_url="https://mybotbox.com"
63
+ )
64
+
65
+ # Execute a workflow
66
+ try:
67
+ result = client.execute_workflow("workflow-id")
68
+ print("Workflow executed successfully:", result)
69
+ except Exception as error:
70
+ print("Workflow execution failed:", error)
71
+ ```
72
+
73
+ ## API Reference
74
+
75
+ ### MyBotBoxClient
76
+
77
+ #### Constructor
78
+
79
+ ```python
80
+ MyBotBoxClient(api_key: str, base_url: str = "https://mybotbox.com")
81
+ ```
82
+
83
+ - `api_key` (str): Your MyBotBox API key
84
+ - `base_url` (str, optional): Base URL for the MyBotBox API (defaults to `https://mybotbox.com`)
85
+
86
+ #### Methods
87
+
88
+ ##### execute_workflow(workflow_id, input_data=None, timeout=30.0)
89
+
90
+ Execute a workflow with optional input data.
91
+
92
+ ```python
93
+ result = client.execute_workflow(
94
+ "workflow-id",
95
+ input_data={"message": "Hello, world!"},
96
+ timeout=30.0 # 30 seconds
97
+ )
98
+ ```
99
+
100
+ **Parameters:**
101
+ - `workflow_id` (str): The ID of the workflow to execute
102
+ - `input_data` (dict, optional): Input data to pass to the workflow. File objects are automatically converted to base64.
103
+ - `timeout` (float): Timeout in seconds (default: 30.0)
104
+
105
+ **Returns:** `WorkflowExecutionResult`
106
+
107
+ ##### get_workflow_status(workflow_id)
108
+
109
+ Get the status of a workflow (deployment status, etc.).
110
+
111
+ ```python
112
+ status = client.get_workflow_status("workflow-id")
113
+ print("Is deployed:", status.is_deployed)
114
+ ```
115
+
116
+ **Parameters:**
117
+ - `workflow_id` (str): The ID of the workflow
118
+
119
+ **Returns:** `WorkflowStatus`
120
+
121
+ ##### validate_workflow(workflow_id)
122
+
123
+ Validate that a workflow is ready for execution.
124
+
125
+ ```python
126
+ is_ready = client.validate_workflow("workflow-id")
127
+ if is_ready:
128
+ # Workflow is deployed and ready
129
+ pass
130
+ ```
131
+
132
+ **Parameters:**
133
+ - `workflow_id` (str): The ID of the workflow
134
+
135
+ **Returns:** `bool`
136
+
137
+ ##### execute_workflow_sync(workflow_id, input_data=None, timeout=30.0)
138
+
139
+ Execute a workflow and poll for completion (useful for long-running workflows).
140
+
141
+ ```python
142
+ result = client.execute_workflow_sync(
143
+ "workflow-id",
144
+ input_data={"data": "some input"},
145
+ timeout=60.0
146
+ )
147
+ ```
148
+
149
+ **Parameters:**
150
+ - `workflow_id` (str): The ID of the workflow to execute
151
+ - `input_data` (dict, optional): Input data to pass to the workflow
152
+ - `timeout` (float): Timeout for the initial request in seconds
153
+
154
+ **Returns:** `WorkflowExecutionResult`
155
+
156
+ ##### set_api_key(api_key)
157
+
158
+ Update the API key.
159
+
160
+ ```python
161
+ client.set_api_key("new-api-key")
162
+ ```
163
+
164
+ ##### set_base_url(base_url)
165
+
166
+ Update the base URL.
167
+
168
+ ```python
169
+ client.set_base_url("https://my-custom-domain.com")
170
+ ```
171
+
172
+ ##### close()
173
+
174
+ Close the underlying HTTP session.
175
+
176
+ ```python
177
+ client.close()
178
+ ```
179
+
180
+ ## Data Classes
181
+
182
+ ### WorkflowExecutionResult
183
+
184
+ ```python
185
+ @dataclass
186
+ class WorkflowExecutionResult:
187
+ success: bool
188
+ output: Optional[Any] = None
189
+ error: Optional[str] = None
190
+ logs: Optional[list] = None
191
+ metadata: Optional[Dict[str, Any]] = None
192
+ trace_spans: Optional[list] = None
193
+ total_duration: Optional[float] = None
194
+ ```
195
+
196
+ ### WorkflowStatus
197
+
198
+ ```python
199
+ @dataclass
200
+ class WorkflowStatus:
201
+ is_deployed: bool
202
+ deployed_at: Optional[str] = None
203
+ is_published: bool = False
204
+ needs_redeployment: bool = False
205
+ ```
206
+
207
+ ### MyBotBoxError
208
+
209
+ ```python
210
+ class MyBotBoxError(Exception):
211
+ def __init__(self, message: str, code: Optional[str] = None, status: Optional[int] = None):
212
+ super().__init__(message)
213
+ self.code = code
214
+ self.status = status
215
+ ```
216
+
217
+ ## Examples
218
+
219
+ ### Basic Workflow Execution
220
+
221
+ ```python
222
+ import os
223
+ from mybotbox import MyBotBoxClient
224
+
225
+ client = MyBotBoxClient(api_key=os.getenv("MBB_API_KEY"))
226
+
227
+ def run_workflow():
228
+ try:
229
+ # Check if workflow is ready
230
+ is_ready = client.validate_workflow("my-workflow-id")
231
+ if not is_ready:
232
+ raise Exception("Workflow is not deployed or ready")
233
+
234
+ # Execute the workflow
235
+ result = client.execute_workflow(
236
+ "my-workflow-id",
237
+ input_data={
238
+ "message": "Process this data",
239
+ "user_id": "12345"
240
+ }
241
+ )
242
+
243
+ if result.success:
244
+ print("Output:", result.output)
245
+ print("Duration:", result.metadata.get("duration") if result.metadata else None)
246
+ else:
247
+ print("Workflow failed:", result.error)
248
+
249
+ except Exception as error:
250
+ print("Error:", error)
251
+
252
+ run_workflow()
253
+ ```
254
+
255
+ ### Error Handling
256
+
257
+ ```python
258
+ from mybotbox import MyBotBoxClient, MyBotBoxError
259
+ import os
260
+
261
+ client = MyBotBoxClient(api_key=os.getenv("MBB_API_KEY"))
262
+
263
+ def execute_with_error_handling():
264
+ try:
265
+ result = client.execute_workflow("workflow-id")
266
+ return result
267
+ except MyBotBoxError as error:
268
+ if error.code == "UNAUTHORIZED":
269
+ print("Invalid API key")
270
+ elif error.code == "TIMEOUT":
271
+ print("Workflow execution timed out")
272
+ elif error.code == "USAGE_LIMIT_EXCEEDED":
273
+ print("Usage limit exceeded")
274
+ elif error.code == "INVALID_JSON":
275
+ print("Invalid JSON in request body")
276
+ else:
277
+ print(f"Workflow error: {error}")
278
+ raise
279
+ except Exception as error:
280
+ print(f"Unexpected error: {error}")
281
+ raise
282
+ ```
283
+
284
+ ### Context Manager Usage
285
+
286
+ ```python
287
+ from mybotbox import MyBotBoxClient
288
+ import os
289
+
290
+ # Using context manager to automatically close the session
291
+ with MyBotBoxClient(api_key=os.getenv("MBB_API_KEY")) as client:
292
+ result = client.execute_workflow("workflow-id")
293
+ print("Result:", result)
294
+ # Session is automatically closed here
295
+ ```
296
+
297
+ ### Environment Configuration
298
+
299
+ ```python
300
+ import os
301
+ from mybotbox import MyBotBoxClient
302
+
303
+ # Using environment variables
304
+ client = MyBotBoxClient(
305
+ api_key=os.getenv("MBB_API_KEY"),
306
+ base_url=os.getenv("YSTUDIO_BASE_URL", "https://mybotbox.com")
307
+ )
308
+ ```
309
+
310
+ ### File Upload
311
+
312
+ File objects are automatically detected and converted to base64 format. Include them in your input under the field name matching your workflow's API trigger input format:
313
+
314
+ The SDK converts file objects to this format:
315
+ ```python
316
+ {
317
+ 'type': 'file',
318
+ 'data': 'data:mime/type;base64,base64data',
319
+ 'name': 'filename',
320
+ 'mime': 'mime/type'
321
+ }
322
+ ```
323
+
324
+ Alternatively, you can manually provide files using the URL format:
325
+ ```python
326
+ {
327
+ 'type': 'url',
328
+ 'data': 'https://example.com/file.pdf',
329
+ 'name': 'file.pdf',
330
+ 'mime': 'application/pdf'
331
+ }
332
+ ```
333
+
334
+ ```python
335
+ from mybotbox import MyBotBoxClient
336
+ import os
337
+
338
+ client = MyBotBoxClient(api_key=os.getenv("MBB_API_KEY"))
339
+
340
+ # Upload a single file - include it under the field name from your API trigger
341
+ with open('document.pdf', 'rb') as f:
342
+ result = client.execute_workflow(
343
+ 'workflow-id',
344
+ input_data={
345
+ 'documents': [f], # Must match your workflow's "files" field name
346
+ 'instructions': 'Analyze this document'
347
+ }
348
+ )
349
+
350
+ # Upload multiple files
351
+ with open('doc1.pdf', 'rb') as f1, open('doc2.pdf', 'rb') as f2:
352
+ result = client.execute_workflow(
353
+ 'workflow-id',
354
+ input_data={
355
+ 'attachments': [f1, f2], # Must match your workflow's "files" field name
356
+ 'query': 'Compare these documents'
357
+ }
358
+ )
359
+ ```
360
+
361
+ ### Batch Workflow Execution
362
+
363
+ ```python
364
+ from mybotbox import MyBotBoxClient
365
+ import os
366
+
367
+ client = MyBotBoxClient(api_key=os.getenv("MBB_API_KEY"))
368
+
369
+ def execute_workflows_batch(workflow_data_pairs):
370
+ """Execute multiple workflows with different input data."""
371
+ results = []
372
+
373
+ for workflow_id, input_data in workflow_data_pairs:
374
+ try:
375
+ # Validate workflow before execution
376
+ if not client.validate_workflow(workflow_id):
377
+ print(f"Skipping {workflow_id}: not deployed")
378
+ continue
379
+
380
+ result = client.execute_workflow(workflow_id, input_data)
381
+ results.append({
382
+ "workflow_id": workflow_id,
383
+ "success": result.success,
384
+ "output": result.output,
385
+ "error": result.error
386
+ })
387
+
388
+ except Exception as error:
389
+ results.append({
390
+ "workflow_id": workflow_id,
391
+ "success": False,
392
+ "error": str(error)
393
+ })
394
+
395
+ return results
396
+
397
+ # Example usage
398
+ workflows = [
399
+ ("workflow-1", {"type": "analysis", "data": "sample1"}),
400
+ ("workflow-2", {"type": "processing", "data": "sample2"}),
401
+ ]
402
+
403
+ results = execute_workflows_batch(workflows)
404
+ for result in results:
405
+ print(f"Workflow {result['workflow_id']}: {'Success' if result['success'] else 'Failed'}")
406
+ ```
407
+
408
+ ## Getting Your API Key
409
+
410
+ 1. Log in to your [MyBotBox]account
411
+ 2. Navigate to your workflow
412
+ 3. Click on "Deploy" to deploy your workflow
413
+ 4. Select or create an API key during the deployment process
414
+ 5. Copy the API key to use in your application
415
+
416
+ ## Development
417
+
418
+ ### Running Tests
419
+
420
+ To run the tests locally:
421
+
422
+ 1. Clone the repository and navigate to the Python SDK directory:
423
+ ```bash
424
+ cd packages/python-sdk
425
+ ```
426
+
427
+ 2. Create and activate a virtual environment:
428
+ ```bash
429
+ python3 -m venv venv
430
+ source venv/bin/activate # On Windows: venv\Scripts\activate
431
+ ```
432
+
433
+ 3. Install the package in development mode with test dependencies:
434
+ ```bash
435
+ pip install -e ".[dev]"
436
+ ```
437
+
438
+ 4. Run the tests:
439
+ ```bash
440
+ pytest tests/ -v
441
+ ```
442
+
443
+ ### Code Quality
444
+
445
+ Run code quality checks:
446
+
447
+ ```bash
448
+ # Code formatting
449
+ black ystudio/
450
+
451
+ # Linting
452
+ flake8 ystudio/ --max-line-length=100
453
+
454
+ # Type checking
455
+ mypy ystudio/
456
+
457
+ # Import sorting
458
+ isort ystudio/
459
+ ```
460
+
461
+ ## Requirements
462
+
463
+ - Python 3.8+
464
+ - requests >= 2.25.0
465
+
466
+ ## License
467
+
468
+ Apache-2.0