syncteams-sdk 0.2.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.
Potentially problematic release.
This version of syncteams-sdk might be problematic. Click here for more details.
- syncteams_sdk-0.2.0/CHANGELOG.md +25 -0
- syncteams_sdk-0.2.0/LICENSE +21 -0
- syncteams_sdk-0.2.0/MANIFEST.in +9 -0
- syncteams_sdk-0.2.0/PKG-INFO +223 -0
- syncteams_sdk-0.2.0/README.md +194 -0
- syncteams_sdk-0.2.0/pyproject.toml +48 -0
- syncteams_sdk-0.2.0/setup.cfg +4 -0
- syncteams_sdk-0.2.0/src/__init__.py +47 -0
- syncteams_sdk-0.2.0/src/_version.py +4 -0
- syncteams_sdk-0.2.0/src/errors.py +61 -0
- syncteams_sdk-0.2.0/src/event_types.py +162 -0
- syncteams_sdk-0.2.0/src/http.py +324 -0
- syncteams_sdk-0.2.0/src/py.typed +0 -0
- syncteams_sdk-0.2.0/src/syncteams_sdk.egg-info/PKG-INFO +223 -0
- syncteams_sdk-0.2.0/src/syncteams_sdk.egg-info/SOURCES.txt +18 -0
- syncteams_sdk-0.2.0/src/syncteams_sdk.egg-info/dependency_links.txt +1 -0
- syncteams_sdk-0.2.0/src/syncteams_sdk.egg-info/requires.txt +7 -0
- syncteams_sdk-0.2.0/src/syncteams_sdk.egg-info/top_level.txt +1 -0
- syncteams_sdk-0.2.0/src/types.py +154 -0
- syncteams_sdk-0.2.0/src/workflow_client.py +253 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.2.0] - 2025-10-28
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Initial Python SDK release
|
|
12
|
+
- `WorkflowClient` with full API support
|
|
13
|
+
- `execute_workflow`, `get_task_status`, `continue_task` methods
|
|
14
|
+
- `wait_for_completion` with polling and callbacks
|
|
15
|
+
- `execute_and_wait` convenience method with approval handling
|
|
16
|
+
- Automatic retry with exponential backoff
|
|
17
|
+
- Type hints and comprehensive error handling
|
|
18
|
+
- Unit tests with pytest
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
- Full parity with JavaScript SDK
|
|
22
|
+
- Python 3.9+ support
|
|
23
|
+
- Async-friendly polling with stop events
|
|
24
|
+
- Webhook event type definitions
|
|
25
|
+
- Detailed error responses with `WorkflowAPIError`
|
|
@@ -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,223 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: syncteams-sdk
|
|
3
|
+
Version: 0.2.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
|
|
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"] == "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
|
+
client.continue_task(task_id=task_id, decision="APPROVE")
|
|
131
|
+
|
|
132
|
+
client.continue_task(
|
|
133
|
+
task_id=task_id,
|
|
134
|
+
decision="REJECT",
|
|
135
|
+
message="Missing documentation",
|
|
136
|
+
)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
When `decision` is `"REJECT"`, `message` is required.
|
|
140
|
+
|
|
141
|
+
### `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)`
|
|
142
|
+
|
|
143
|
+
Polls a task until it reaches a terminal status (`COMPLETED`, `FAILED`, or `CANCELED`).
|
|
144
|
+
|
|
145
|
+
```python
|
|
146
|
+
final_status = client.wait_for_completion(
|
|
147
|
+
task_id,
|
|
148
|
+
poll_interval_ms=1000,
|
|
149
|
+
on_update=lambda payload: print("Status:", payload["status"]),
|
|
150
|
+
)
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
### `execute_and_wait(workflow_id, input, **options)`
|
|
154
|
+
|
|
155
|
+
Convenience method that starts a workflow and optionally handles approvals via `on_waiting`.
|
|
156
|
+
|
|
157
|
+
```python
|
|
158
|
+
def handle_waiting(status):
|
|
159
|
+
# Perform approval logic
|
|
160
|
+
client.continue_task(task_id=status["taskId"], decision="APPROVE")
|
|
161
|
+
return True
|
|
162
|
+
|
|
163
|
+
result = client.execute_and_wait(
|
|
164
|
+
workflow_id="wf-123",
|
|
165
|
+
input={"amount": 500},
|
|
166
|
+
on_waiting=handle_waiting,
|
|
167
|
+
)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
If `on_waiting` returns `False`, polling stops and the SDK returns the current status (even if still waiting).
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
## Error Handling
|
|
175
|
+
|
|
176
|
+
The SDK raises `WorkflowAPIError` for API failures. It exposes the HTTP status, headers, response payload, and request metadata to simplify debugging.
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
from syncteams_sdk import WorkflowAPIError
|
|
180
|
+
|
|
181
|
+
try:
|
|
182
|
+
client.execute_workflow(workflow_id="invalid", input={})
|
|
183
|
+
except WorkflowAPIError as error:
|
|
184
|
+
print("API error:", error.status, error.data)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Transient errors (timeouts, rate limits, server errors) are automatically retried according to the configured policy.
|
|
188
|
+
|
|
189
|
+
---
|
|
190
|
+
|
|
191
|
+
## Webhooks
|
|
192
|
+
|
|
193
|
+
You can receive workflow updates via webhooks instead of polling:
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
from flask import Flask, request
|
|
197
|
+
from syncteams_sdk import WebhookEventPayload
|
|
198
|
+
|
|
199
|
+
app = Flask(__name__)
|
|
200
|
+
|
|
201
|
+
@app.post("/webhooks/syncteams")
|
|
202
|
+
def handle_webhook():
|
|
203
|
+
payload: WebhookEventPayload = request.get_json(force=True)
|
|
204
|
+
print("Task", payload["taskId"], "status:", payload["status"])
|
|
205
|
+
return ("", 200)
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
---
|
|
209
|
+
|
|
210
|
+
## Development
|
|
211
|
+
|
|
212
|
+
Install dependencies and run tests:
|
|
213
|
+
|
|
214
|
+
```bash
|
|
215
|
+
pip install -e .[dev]
|
|
216
|
+
pytest
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## License
|
|
222
|
+
|
|
223
|
+
MIT
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
# SyncTeams Workflow SDK (Python)
|
|
2
|
+
|
|
3
|
+
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.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pip install syncteams-sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
**Requirements:** Python 3.9 or newer
|
|
14
|
+
|
|
15
|
+
---
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from syncteams_sdk import WorkflowClient
|
|
21
|
+
|
|
22
|
+
client = WorkflowClient(api_key="YOUR_API_KEY")
|
|
23
|
+
|
|
24
|
+
# Execute a workflow
|
|
25
|
+
result = client.execute_workflow(
|
|
26
|
+
workflow_id="your_workflow_id",
|
|
27
|
+
input={"email": "user@example.com"},
|
|
28
|
+
unique_id="customer-123",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
task_id = result["taskId"]
|
|
32
|
+
|
|
33
|
+
# Wait for completion
|
|
34
|
+
final_status = client.wait_for_completion(
|
|
35
|
+
task_id,
|
|
36
|
+
poll_interval_ms=2_000,
|
|
37
|
+
on_update=lambda status: print(f"Status: {status['status']}")
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
if final_status["status"] == "COMPLETED":
|
|
41
|
+
print("Workflow completed successfully!")
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Configuration
|
|
47
|
+
|
|
48
|
+
| Option | Required | Default | Description |
|
|
49
|
+
| --- | --- | --- | --- |
|
|
50
|
+
| `api_key` | ✅ | – | Your SyncTeams API key |
|
|
51
|
+
| `base_url` | ❌ | `https://develop.api.syncteams.studio` | API base URL |
|
|
52
|
+
| `timeout_ms` | ❌ | `30000` | Request timeout in milliseconds |
|
|
53
|
+
| `retry` | ❌ | See below | Retry configuration for failed requests |
|
|
54
|
+
| `default_headers` | ❌ | `{}` | Extra headers merged into every request |
|
|
55
|
+
| `user_agent_suffix` | ❌ | – | Extra token appended to the default User-Agent |
|
|
56
|
+
|
|
57
|
+
### Retry Configuration
|
|
58
|
+
|
|
59
|
+
By default, the SDK retries transient failures with exponential backoff:
|
|
60
|
+
- Maximum attempts: 3
|
|
61
|
+
- Initial delay: 1 second
|
|
62
|
+
- Backoff factor: 2x
|
|
63
|
+
- Maximum delay: 30 seconds
|
|
64
|
+
- Retries on: 408, 425, 429, and all 5xx responses
|
|
65
|
+
|
|
66
|
+
You can override any subset of these values when constructing the client.
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## API overview
|
|
71
|
+
|
|
72
|
+
### `execute_workflow(workflow_id, input, unique_id=None)`
|
|
73
|
+
|
|
74
|
+
Starts a workflow execution.
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
response = client.execute_workflow(
|
|
78
|
+
workflow_id="your_workflow_id",
|
|
79
|
+
input={"customer_id": "cust-123"},
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
print(response["taskId"], response["status"])
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Returns the `taskId` and initial status.
|
|
86
|
+
|
|
87
|
+
### `get_task_status(task_id)`
|
|
88
|
+
|
|
89
|
+
Fetches the latest status and the filtered event log for a task.
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
status = client.get_task_status(task_id)
|
|
93
|
+
print(status["status"], len(status.get("eventLogs", [])))
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### `continue_task(task_id, decision, message=None)`
|
|
97
|
+
|
|
98
|
+
Resumes a waiting workflow after an approval decision.
|
|
99
|
+
|
|
100
|
+
```python
|
|
101
|
+
client.continue_task(task_id=task_id, decision="APPROVE")
|
|
102
|
+
|
|
103
|
+
client.continue_task(
|
|
104
|
+
task_id=task_id,
|
|
105
|
+
decision="REJECT",
|
|
106
|
+
message="Missing documentation",
|
|
107
|
+
)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
When `decision` is `"REJECT"`, `message` is required.
|
|
111
|
+
|
|
112
|
+
### `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)`
|
|
113
|
+
|
|
114
|
+
Polls a task until it reaches a terminal status (`COMPLETED`, `FAILED`, or `CANCELED`).
|
|
115
|
+
|
|
116
|
+
```python
|
|
117
|
+
final_status = client.wait_for_completion(
|
|
118
|
+
task_id,
|
|
119
|
+
poll_interval_ms=1000,
|
|
120
|
+
on_update=lambda payload: print("Status:", payload["status"]),
|
|
121
|
+
)
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### `execute_and_wait(workflow_id, input, **options)`
|
|
125
|
+
|
|
126
|
+
Convenience method that starts a workflow and optionally handles approvals via `on_waiting`.
|
|
127
|
+
|
|
128
|
+
```python
|
|
129
|
+
def handle_waiting(status):
|
|
130
|
+
# Perform approval logic
|
|
131
|
+
client.continue_task(task_id=status["taskId"], decision="APPROVE")
|
|
132
|
+
return True
|
|
133
|
+
|
|
134
|
+
result = client.execute_and_wait(
|
|
135
|
+
workflow_id="wf-123",
|
|
136
|
+
input={"amount": 500},
|
|
137
|
+
on_waiting=handle_waiting,
|
|
138
|
+
)
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
If `on_waiting` returns `False`, polling stops and the SDK returns the current status (even if still waiting).
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## Error Handling
|
|
146
|
+
|
|
147
|
+
The SDK raises `WorkflowAPIError` for API failures. It exposes the HTTP status, headers, response payload, and request metadata to simplify debugging.
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
from syncteams_sdk import WorkflowAPIError
|
|
151
|
+
|
|
152
|
+
try:
|
|
153
|
+
client.execute_workflow(workflow_id="invalid", input={})
|
|
154
|
+
except WorkflowAPIError as error:
|
|
155
|
+
print("API error:", error.status, error.data)
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Transient errors (timeouts, rate limits, server errors) are automatically retried according to the configured policy.
|
|
159
|
+
|
|
160
|
+
---
|
|
161
|
+
|
|
162
|
+
## Webhooks
|
|
163
|
+
|
|
164
|
+
You can receive workflow updates via webhooks instead of polling:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from flask import Flask, request
|
|
168
|
+
from syncteams_sdk import WebhookEventPayload
|
|
169
|
+
|
|
170
|
+
app = Flask(__name__)
|
|
171
|
+
|
|
172
|
+
@app.post("/webhooks/syncteams")
|
|
173
|
+
def handle_webhook():
|
|
174
|
+
payload: WebhookEventPayload = request.get_json(force=True)
|
|
175
|
+
print("Task", payload["taskId"], "status:", payload["status"])
|
|
176
|
+
return ("", 200)
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
---
|
|
180
|
+
|
|
181
|
+
## Development
|
|
182
|
+
|
|
183
|
+
Install dependencies and run tests:
|
|
184
|
+
|
|
185
|
+
```bash
|
|
186
|
+
pip install -e .[dev]
|
|
187
|
+
pytest
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
---
|
|
191
|
+
|
|
192
|
+
## License
|
|
193
|
+
|
|
194
|
+
MIT
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68.0.0,<77", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "syncteams-sdk"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Python client for the SyncTeams Workflow API"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "SyncTeams", email = "support@syncteams.studio"}
|
|
13
|
+
]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"requests>=2.31.0",
|
|
16
|
+
"typing-extensions>=4.8.0"
|
|
17
|
+
]
|
|
18
|
+
keywords = ["workflow", "automation", "syncteams", "sdk"]
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 3 - Alpha",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"License :: OSI Approved :: MIT License",
|
|
23
|
+
"Programming Language :: Python",
|
|
24
|
+
"Programming Language :: Python :: 3",
|
|
25
|
+
"Programming Language :: Python :: 3.9",
|
|
26
|
+
"Programming Language :: Python :: 3.10",
|
|
27
|
+
"Programming Language :: Python :: 3.11",
|
|
28
|
+
"Programming Language :: Python :: 3.12",
|
|
29
|
+
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
dev = [
|
|
34
|
+
"pytest>=7.4",
|
|
35
|
+
"responses>=0.25.0",
|
|
36
|
+
"coverage>=7.3"
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://develop.syncteams.studio"
|
|
41
|
+
Repository = "https://github.com/syncteamsstudio/python-sdk.git"
|
|
42
|
+
Documentation = "https://develop.syncteams.studio"
|
|
43
|
+
|
|
44
|
+
[tool.setuptools]
|
|
45
|
+
package-dir = {"" = "src"}
|
|
46
|
+
|
|
47
|
+
[tool.setuptools.packages.find]
|
|
48
|
+
where = ["src"]
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"""Public package API for the SyncTeams Workflow Python SDK."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from ._version import __version__
|
|
5
|
+
from .errors import WorkflowAPIError, is_workflow_api_error
|
|
6
|
+
from .types import (
|
|
7
|
+
ApprovalDecision,
|
|
8
|
+
DEFAULT_BASE_URL,
|
|
9
|
+
DEFAULT_MAX_WAIT_TIME_MS,
|
|
10
|
+
DEFAULT_POLL_INTERVAL_MS,
|
|
11
|
+
DEFAULT_REQUEST_TIMEOUT_MS,
|
|
12
|
+
ExecuteAndWaitOptions,
|
|
13
|
+
ExecuteWorkflowInput,
|
|
14
|
+
ExecuteWorkflowResponse,
|
|
15
|
+
TaskEventLog,
|
|
16
|
+
TaskStatusResponse,
|
|
17
|
+
WaitForCompletionOptions,
|
|
18
|
+
WebhookEventPayload,
|
|
19
|
+
WorkflowClientOptions,
|
|
20
|
+
WorkflowClientRetryConfig,
|
|
21
|
+
WorkflowEventType,
|
|
22
|
+
WorkflowStatus,
|
|
23
|
+
)
|
|
24
|
+
from .workflow_client import WorkflowClient
|
|
25
|
+
|
|
26
|
+
__all__ = [
|
|
27
|
+
"WorkflowClient",
|
|
28
|
+
"WorkflowAPIError",
|
|
29
|
+
"is_workflow_api_error",
|
|
30
|
+
"WorkflowStatus",
|
|
31
|
+
"WorkflowEventType",
|
|
32
|
+
"ApprovalDecision",
|
|
33
|
+
"TaskEventLog",
|
|
34
|
+
"ExecuteWorkflowInput",
|
|
35
|
+
"ExecuteWorkflowResponse",
|
|
36
|
+
"TaskStatusResponse",
|
|
37
|
+
"WebhookEventPayload",
|
|
38
|
+
"WorkflowClientOptions",
|
|
39
|
+
"WorkflowClientRetryConfig",
|
|
40
|
+
"WaitForCompletionOptions",
|
|
41
|
+
"ExecuteAndWaitOptions",
|
|
42
|
+
"DEFAULT_REQUEST_TIMEOUT_MS",
|
|
43
|
+
"DEFAULT_POLL_INTERVAL_MS",
|
|
44
|
+
"DEFAULT_MAX_WAIT_TIME_MS",
|
|
45
|
+
"DEFAULT_BASE_URL",
|
|
46
|
+
"__version__",
|
|
47
|
+
]
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""Custom exceptions raised by the SyncTeams Python SDK."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Any, Dict, Mapping, MutableMapping, Optional, Union
|
|
6
|
+
|
|
7
|
+
from .types import Headers, RequestDescriptor
|
|
8
|
+
|
|
9
|
+
ErrorResponseData = Union[Mapping[str, Any], str, None]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class WorkflowAPIErrorRequest:
|
|
14
|
+
method: str
|
|
15
|
+
url: str
|
|
16
|
+
body: Optional[Any] = None
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class WorkflowAPIError(Exception):
|
|
20
|
+
"""Raised when the SyncTeams API returns an error response."""
|
|
21
|
+
|
|
22
|
+
def __init__(
|
|
23
|
+
self,
|
|
24
|
+
*,
|
|
25
|
+
message: str,
|
|
26
|
+
status: int,
|
|
27
|
+
status_text: str,
|
|
28
|
+
headers: Mapping[str, str] | Headers,
|
|
29
|
+
data: ErrorResponseData,
|
|
30
|
+
request: RequestDescriptor,
|
|
31
|
+
cause: Exception | None = None,
|
|
32
|
+
) -> None:
|
|
33
|
+
super().__init__(message)
|
|
34
|
+
self.status = status
|
|
35
|
+
self.status_text = status_text
|
|
36
|
+
self.headers = dict(headers)
|
|
37
|
+
self.data = data
|
|
38
|
+
self.request = request
|
|
39
|
+
self.cause = cause
|
|
40
|
+
|
|
41
|
+
def __repr__(self) -> str: # pragma: no cover - repr convenience
|
|
42
|
+
return (
|
|
43
|
+
f"WorkflowAPIError(status={self.status!r}, message={self.args[0]!r}, "
|
|
44
|
+
f"url={self.request.url!r})"
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def is_workflow_api_error(error: Exception) -> bool:
|
|
49
|
+
"""Return ``True`` if *error* is a :class:`WorkflowAPIError`."""
|
|
50
|
+
|
|
51
|
+
return isinstance(error, WorkflowAPIError)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def normalize_headers(headers: Mapping[str, str] | Headers | None) -> Dict[str, str]:
|
|
55
|
+
if headers is None:
|
|
56
|
+
return {}
|
|
57
|
+
|
|
58
|
+
if isinstance(headers, MutableMapping):
|
|
59
|
+
return dict(headers)
|
|
60
|
+
|
|
61
|
+
return {key: value for key, value in headers.items()}
|