syncteams-sdk 0.3.0__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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 SyncTeams
|
|
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,261 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: syncteams-sdk
|
|
3
|
+
Version: 0.3.0
|
|
4
|
+
Summary: Python client for the SyncTeams Workflow API
|
|
5
|
+
Author-email: SyncTeams <support@syncteams.studio>
|
|
6
|
+
Project-URL: Homepage, https://develop.syncteams.studio
|
|
7
|
+
Project-URL: Repository, https://github.com/syncteamsstudio/python-sdk.git
|
|
8
|
+
Project-URL: Documentation, https://develop.syncteams.studio
|
|
9
|
+
Keywords: workflow,automation,syncteams,sdk
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
20
|
+
Requires-Python: >=3.9
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
License-File: LICENSE
|
|
23
|
+
Requires-Dist: requests>=2.31.0
|
|
24
|
+
Requires-Dist: typing-extensions>=4.8.0
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: pytest>=7.4; extra == "dev"
|
|
27
|
+
Requires-Dist: responses>=0.25.0; extra == "dev"
|
|
28
|
+
Requires-Dist: coverage>=7.3; extra == "dev"
|
|
29
|
+
|
|
30
|
+
# SyncTeams Workflow SDK (Python)
|
|
31
|
+
|
|
32
|
+
A Python client for the SyncTeams Workflow API. Mirrors the capabilities of the JavaScript SDK, offering convenient helpers to execute workflows, monitor task status, and manage approval flows.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install syncteams-sdk
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
**Requirements:** Python 3.9 or newer
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Quick Start
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from syncteams_sdk import WorkflowClient, WorkflowStatus
|
|
50
|
+
|
|
51
|
+
client = WorkflowClient(api_key="YOUR_API_KEY")
|
|
52
|
+
|
|
53
|
+
# Execute a workflow
|
|
54
|
+
result = client.execute_workflow(
|
|
55
|
+
workflow_id="your_workflow_id",
|
|
56
|
+
input={"email": "user@example.com"},
|
|
57
|
+
unique_id="customer-123",
|
|
58
|
+
)
|
|
59
|
+
|
|
60
|
+
task_id = result["taskId"]
|
|
61
|
+
|
|
62
|
+
# Wait for completion
|
|
63
|
+
final_status = client.wait_for_completion(
|
|
64
|
+
task_id,
|
|
65
|
+
poll_interval_ms=2_000,
|
|
66
|
+
on_update=lambda status: print(f"Status: {status['status']}")
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
if final_status["status"] == WorkflowStatus.COMPLETED:
|
|
70
|
+
print("Workflow completed successfully!")
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## Configuration
|
|
76
|
+
|
|
77
|
+
| Option | Required | Default | Description |
|
|
78
|
+
| --- | --- | --- | --- |
|
|
79
|
+
| `api_key` | ✅ | – | Your SyncTeams API key |
|
|
80
|
+
| `base_url` | ❌ | `https://develop.api.syncteams.studio` | API base URL |
|
|
81
|
+
| `timeout_ms` | ❌ | `30000` | Request timeout in milliseconds |
|
|
82
|
+
| `retry` | ❌ | See below | Retry configuration for failed requests |
|
|
83
|
+
| `default_headers` | ❌ | `{}` | Extra headers merged into every request |
|
|
84
|
+
| `user_agent_suffix` | ❌ | – | Extra token appended to the default User-Agent |
|
|
85
|
+
|
|
86
|
+
### Retry Configuration
|
|
87
|
+
|
|
88
|
+
By default, the SDK retries transient failures with exponential backoff:
|
|
89
|
+
- Maximum attempts: 3
|
|
90
|
+
- Initial delay: 1 second
|
|
91
|
+
- Backoff factor: 2x
|
|
92
|
+
- Maximum delay: 30 seconds
|
|
93
|
+
- Retries on: 408, 425, 429, and all 5xx responses
|
|
94
|
+
|
|
95
|
+
You can override any subset of these values when constructing the client.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## API overview
|
|
100
|
+
|
|
101
|
+
### `execute_workflow(workflow_id, input, unique_id=None)`
|
|
102
|
+
|
|
103
|
+
Starts a workflow execution.
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
response = client.execute_workflow(
|
|
107
|
+
workflow_id="your_workflow_id",
|
|
108
|
+
input={"customer_id": "cust-123"},
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
print(response["taskId"], response["status"])
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Returns the `taskId` and initial status.
|
|
115
|
+
|
|
116
|
+
### `get_task_status(task_id)`
|
|
117
|
+
|
|
118
|
+
Fetches the latest status and the filtered event log for a task.
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
status = client.get_task_status(task_id)
|
|
122
|
+
print(status["status"], len(status.get("eventLogs", [])))
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### `continue_task(task_id, decision, message=None)`
|
|
126
|
+
|
|
127
|
+
Resumes a waiting workflow after an approval decision.
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from syncteams_sdk import ApprovalDecision
|
|
131
|
+
|
|
132
|
+
client.continue_task(task_id=task_id, decision=ApprovalDecision.APPROVE)
|
|
133
|
+
|
|
134
|
+
client.continue_task(
|
|
135
|
+
task_id=task_id,
|
|
136
|
+
decision=ApprovalDecision.REJECT,
|
|
137
|
+
message="Missing documentation",
|
|
138
|
+
)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
When `decision` is `ApprovalDecision.REJECT`, `message` is required.
|
|
142
|
+
|
|
143
|
+
### `wait_for_completion(task_id, *, poll_interval_ms=2000, max_wait_time_ms=600000, on_update=None, exit_on_waiting=False, terminal_statuses=None, stop_event=None)`
|
|
144
|
+
|
|
145
|
+
Polls a task until it reaches a terminal status (`COMPLETED`, `FAILED`, or `CANCELED`).
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
final_status = client.wait_for_completion(
|
|
149
|
+
task_id,
|
|
150
|
+
poll_interval_ms=1000,
|
|
151
|
+
on_update=lambda payload: print("Status:", payload["status"]),
|
|
152
|
+
)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### `execute_and_wait(workflow_id, input, **options)`
|
|
156
|
+
|
|
157
|
+
Convenience method that starts a workflow and optionally handles approvals via `on_waiting`.
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
from syncteams_sdk import ApprovalDecision
|
|
161
|
+
|
|
162
|
+
def handle_waiting(status):
|
|
163
|
+
# Perform approval logic
|
|
164
|
+
client.continue_task(task_id=status["taskId"], decision=ApprovalDecision.APPROVE)
|
|
165
|
+
return True
|
|
166
|
+
|
|
167
|
+
result = client.execute_and_wait(
|
|
168
|
+
workflow_id="wf-123",
|
|
169
|
+
input={"amount": 500},
|
|
170
|
+
on_waiting=handle_waiting,
|
|
171
|
+
)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
If `on_waiting` returns `False`, polling stops and the SDK returns the current status (even if still waiting).
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## Error Handling
|
|
179
|
+
|
|
180
|
+
The SDK raises `WorkflowAPIError` for API failures. It exposes the HTTP status, headers, response payload, and request metadata to simplify debugging.
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
from syncteams_sdk import WorkflowAPIError
|
|
184
|
+
|
|
185
|
+
try:
|
|
186
|
+
client.execute_workflow(workflow_id="invalid", input={})
|
|
187
|
+
except WorkflowAPIError as error:
|
|
188
|
+
print("API error:", error.status, error.data)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Transient errors (timeouts, rate limits, server errors) are automatically retried according to the configured policy.
|
|
192
|
+
|
|
193
|
+
---
|
|
194
|
+
|
|
195
|
+
## Webhooks
|
|
196
|
+
|
|
197
|
+
You can receive workflow updates via webhooks instead of polling:
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
from flask import Flask, request
|
|
201
|
+
from syncteams_sdk import WebhookEventPayload
|
|
202
|
+
|
|
203
|
+
app = Flask(__name__)
|
|
204
|
+
|
|
205
|
+
@app.post("/webhooks/syncteams")
|
|
206
|
+
def handle_webhook():
|
|
207
|
+
payload: WebhookEventPayload = request.get_json(force=True)
|
|
208
|
+
print("Task", payload["taskId"], "status:", payload["status"])
|
|
209
|
+
return ("", 200)
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
---
|
|
213
|
+
|
|
214
|
+
## Type Safety with Enums
|
|
215
|
+
|
|
216
|
+
The SDK provides enums for better type safety and IDE autocomplete:
|
|
217
|
+
|
|
218
|
+
```python
|
|
219
|
+
from syncteams_sdk import WorkflowStatus, ApprovalDecision, WorkflowEventType
|
|
220
|
+
|
|
221
|
+
# Use enums for type-safe comparisons
|
|
222
|
+
if status["status"] == WorkflowStatus.COMPLETED:
|
|
223
|
+
# Handle completion
|
|
224
|
+
pass
|
|
225
|
+
|
|
226
|
+
# All available workflow statuses
|
|
227
|
+
WorkflowStatus.QUEUED
|
|
228
|
+
WorkflowStatus.PENDING
|
|
229
|
+
WorkflowStatus.RUNNING
|
|
230
|
+
WorkflowStatus.WAITING
|
|
231
|
+
WorkflowStatus.CANCELED
|
|
232
|
+
WorkflowStatus.FAILED
|
|
233
|
+
WorkflowStatus.COMPLETED
|
|
234
|
+
|
|
235
|
+
# Approval decisions
|
|
236
|
+
ApprovalDecision.APPROVE
|
|
237
|
+
ApprovalDecision.REJECT
|
|
238
|
+
|
|
239
|
+
# Enums work seamlessly with the API
|
|
240
|
+
client.continue_task(
|
|
241
|
+
task_id=task_id,
|
|
242
|
+
decision=ApprovalDecision.APPROVE # Type-safe!
|
|
243
|
+
)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
---
|
|
247
|
+
|
|
248
|
+
## Development
|
|
249
|
+
|
|
250
|
+
Install dependencies and run tests:
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
pip install -e .[dev]
|
|
254
|
+
pytest
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
---
|
|
258
|
+
|
|
259
|
+
## License
|
|
260
|
+
|
|
261
|
+
MIT
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
syncteams_sdk-0.3.0.dist-info/LICENSE,sha256=HpkUQoEdxz-kqHWYeuZIDPBruqySo3TQ_Cx9XHPqmiI,1066
|
|
2
|
+
syncteams_sdk-0.3.0.dist-info/METADATA,sha256=p4LgAko_CxnV2TeAcBXy4Ep7YOopLsKNw5TwlnCyvN4,6766
|
|
3
|
+
syncteams_sdk-0.3.0.dist-info/WHEEL,sha256=beeZ86-EfXScwlR_HKu4SllMC9wUEj_8Z_4FJ3egI2w,91
|
|
4
|
+
syncteams_sdk-0.3.0.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
5
|
+
syncteams_sdk-0.3.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|