Skip to main content

Python client for the SyncTeams Workflow API

Project description

SyncTeams Workflow SDK (Python)

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.


Installation

pip install syncteams-sdk

Requirements: Python 3.9 or newer


Quick Start

from syncteams_sdk import WorkflowClient

client = WorkflowClient(api_key="YOUR_API_KEY")

# Execute a workflow
result = client.execute_workflow(
    workflow_id="your_workflow_id",
    input={"email": "user@example.com"},
    unique_id="customer-123",
)

task_id = result["taskId"]

# Wait for completion
final_status = client.wait_for_completion(
    task_id,
    poll_interval_ms=2_000,
    on_update=lambda status: print(f"Status: {status['status']}")
)

if final_status["status"] == "COMPLETED":
    print("Workflow completed successfully!")

Configuration

Option Required Default Description
api_key Your SyncTeams API key
base_url https://develop.api.syncteams.studio API base URL
timeout_ms 30000 Request timeout in milliseconds
retry See below Retry configuration for failed requests
default_headers {} Extra headers merged into every request
user_agent_suffix Extra token appended to the default User-Agent

Retry Configuration

By default, the SDK retries transient failures with exponential backoff:

  • Maximum attempts: 3
  • Initial delay: 1 second
  • Backoff factor: 2x
  • Maximum delay: 30 seconds
  • Retries on: 408, 425, 429, and all 5xx responses

You can override any subset of these values when constructing the client.


API overview

execute_workflow(workflow_id, input, unique_id=None)

Starts a workflow execution.

response = client.execute_workflow(
    workflow_id="your_workflow_id",
    input={"customer_id": "cust-123"},
)

print(response["taskId"], response["status"])

Returns the taskId and initial status.

get_task_status(task_id)

Fetches the latest status and the filtered event log for a task.

status = client.get_task_status(task_id)
print(status["status"], len(status.get("eventLogs", [])))

continue_task(task_id, decision, message=None)

Resumes a waiting workflow after an approval decision.

client.continue_task(task_id=task_id, decision="APPROVE")

client.continue_task(
    task_id=task_id,
    decision="REJECT",
    message="Missing documentation",
)

When decision is "REJECT", message is required.

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)

Polls a task until it reaches a terminal status (COMPLETED, FAILED, or CANCELED).

final_status = client.wait_for_completion(
    task_id,
    poll_interval_ms=1000,
    on_update=lambda payload: print("Status:", payload["status"]),
)

execute_and_wait(workflow_id, input, **options)

Convenience method that starts a workflow and optionally handles approvals via on_waiting.

def handle_waiting(status):
    # Perform approval logic
    client.continue_task(task_id=status["taskId"], decision="APPROVE")
    return True

result = client.execute_and_wait(
    workflow_id="wf-123",
    input={"amount": 500},
    on_waiting=handle_waiting,
)

If on_waiting returns False, polling stops and the SDK returns the current status (even if still waiting).


Error Handling

The SDK raises WorkflowAPIError for API failures. It exposes the HTTP status, headers, response payload, and request metadata to simplify debugging.

from syncteams_sdk import WorkflowAPIError

try:
    client.execute_workflow(workflow_id="invalid", input={})
except WorkflowAPIError as error:
    print("API error:", error.status, error.data)

Transient errors (timeouts, rate limits, server errors) are automatically retried according to the configured policy.


Webhooks

You can receive workflow updates via webhooks instead of polling:

from flask import Flask, request
from syncteams_sdk import WebhookEventPayload

app = Flask(__name__)

@app.post("/webhooks/syncteams")
def handle_webhook():
    payload: WebhookEventPayload = request.get_json(force=True)
    print("Task", payload["taskId"], "status:", payload["status"])
    return ("", 200)

Development

Install dependencies and run tests:

pip install -e .[dev]
pytest

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

syncteams_sdk-0.2.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

syncteams_sdk-0.2.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file syncteams_sdk-0.2.0.tar.gz.

File metadata

  • Download URL: syncteams_sdk-0.2.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for syncteams_sdk-0.2.0.tar.gz
Algorithm Hash digest
SHA256 70e2d7fa0d6ba9cfab44707eb3fd205e690d4162054f75a01663353e54035fa6
MD5 48427f7a3fcd4b134cb86f8b00bab3f0
BLAKE2b-256 b806ae6d2502f14d175b81f3dc31c7e073d9a1062c8053fcadf094e4a40b1fbb

See more details on using hashes here.

File details

Details for the file syncteams_sdk-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: syncteams_sdk-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.10

File hashes

Hashes for syncteams_sdk-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cf112d1a25a75884ae6223ceb698b50e83df8ea7d3a08183b1f4786f79abb553
MD5 4dcc9652a67782de12fad00fba02263a
BLAKE2b-256 5502210876704a853589efe4683e700ab437f5caf1b838d8006be7f524aa6658

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page