Metadata-Version: 2.5
Name: lumaflow-sdk
Version: 0.1.0a1
Summary: Python client for the Luma Flow business workflow API
Project-URL: Homepage, https://songhonglei.github.io/LumaFlow/
Project-URL: Documentation, https://github.com/Songhonglei/LumaFlow/blob/main/docs/lumaflow-python.md
Project-URL: Repository, https://github.com/Songhonglei/LumaFlow
Project-URL: Issues, https://github.com/Songhonglei/LumaFlow/issues
Author: Evan Song
License-Expression: MIT
License-File: LICENSE
Classifier: Development Status :: 3 - Alpha
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.11
Description-Content-Type: text/markdown

# Luma Flow Python SDK

Connect Python services to a self-hosted Luma Flow instance. The first alpha
supports Python 3.11 and later and uses only the Python standard library at runtime.
It requires a Luma Flow server with the `/api/work/v1` business API and Webhook
support. The SDK uses published workflow versions.

[Self-hosting](https://github.com/Songhonglei/LumaFlow/blob/main/docs/lumaflow-self-host.md) ·
[中文指南](https://github.com/Songhonglei/LumaFlow/blob/main/docs/lumaflow-python.md)

## Install from source

From the Luma Flow repository root:

```sh
python3 -m pip install ./sdk/python
```

## Submit and read a task

Use a personal access token from the server. Set `LUMAFLOW_URL` to its base URL
and supply `LUMAFLOW_TOKEN` from your credential store. Use HTTPS for remote
services. Use stable IDs and event keys in integrations that run unattended.

```python
import os
from lumaflow import LumaFlowClient

client = LumaFlowClient(os.environ["LUMAFLOW_URL"], os.environ["LUMAFLOW_TOKEN"])
spaces = client.list_spaces()
apps = client.list_apps(spaces[0]["id"])
workflows = client.list_workflows(apps[0]["id"])

# Example for the supplier review workflow. Use your workflow's fields.
run = client.start_run(
    apps[0]["id"],
    workflows[0]["id"],
    {"supplier": "Example A", "summary": "New supplier", "kind": "已补齐"},
    idempotency_key="supplier-request-001",
)
result = client.get_run(run["id"])
print(result["status"])
for artifact in result["evidence"]:
    data = client.get_evidence(run["id"], artifact["id"], attempt=artifact["attempt"])
    print(artifact["name"], data)
```

The task may still be queued, running, or awaiting approval when queried.
The example assumes that the first workspace, workbench and workflow are the
supplier review example. Inspect `fields` to obtain the exact keys and options
for your workflow. A text attachment uses `{"name": "proof.txt", "text": "..."}`.

## Trigger a Webhook

Use the full endpoint and dedicated key from the trigger's configuration.
The Webhook returns a run ID. Query it with a personal token for an account
with access to the run.

```python
import os
from lumaflow import trigger_webhook

run_id = trigger_webhook(
    os.environ["LUMAFLOW_WEBHOOK_URL"],
    os.environ["LUMAFLOW_WEBHOOK_TOKEN"],
    {"supplier": "Example A", "summary": "New supplier", "kind": "已补齐"},
    idempotency_key="supplier-event-001",
)
```

Use the same ASCII idempotency key and input if you retry the same submission.
A conflicting reuse of a key can return HTTP 409. The SDK does not retry or
follow redirects. `APIError.status_code` carries the server's HTTP status.
`TransportError` means the exchange failed and submission may already have been
accepted. `ProtocolError` signals an unexpected success response. The default
timeout is 30 seconds and can be set with `timeout=`.
