Skip to main content

Official Python SDK for FlowMaestro

Project description

FlowMaestro Python SDK

Official Python SDK for FlowMaestro.

Installation

pip install flowmaestro

Quick Start

Synchronous Client

from flowmaestro import FlowMaestroClient

with FlowMaestroClient(api_key="fm_live_...") as client:
    # Execute a workflow
    response = client.workflows.execute("wf_123", inputs={"name": "John"})
    execution_id = response["data"]["execution_id"]

    # Wait for completion
    result = client.executions.wait_for_completion(execution_id)
    print(f"Result: {result['outputs']}")

Async Client

import asyncio
from flowmaestro import AsyncFlowMaestroClient

async def main():
    async with AsyncFlowMaestroClient(api_key="fm_live_...") as client:
        # Execute a workflow
        response = await client.workflows.execute("wf_123", inputs={"name": "John"})
        execution_id = response["data"]["execution_id"]

        # Wait for completion
        result = await client.executions.wait_for_completion(execution_id)
        print(f"Result: {result['outputs']}")

asyncio.run(main())

Features

  • Workflows: List, get, and execute workflows
  • Executions: Track, stream, and cancel executions
  • Agents: List agents and create conversation threads
  • Threads: Send messages with streaming support
  • Triggers: List and execute workflow triggers
  • Knowledge Bases: Semantic search across your knowledge bases
  • Webhooks: Manage outgoing webhooks
  • Sync & Async: Both synchronous and async clients

API Reference

Client Configuration

client = FlowMaestroClient(
    api_key="fm_live_...",           # Required: Your API key
    base_url="https://api.flowmaestro.io",  # Optional: API base URL
    timeout=30.0,                     # Optional: Request timeout (seconds)
    max_retries=3                     # Optional: Max retry attempts
)

Workflows

# List all workflows
response = client.workflows.list()

# Get a specific workflow
response = client.workflows.get("wf_123")

# Execute a workflow
response = client.workflows.execute("wf_123", inputs={
    "name": "John",
    "email": "john@example.com"
})

Executions

# List executions
response = client.executions.list(workflow_id="wf_123", status="running")

# Get execution details
response = client.executions.get("exec_123")

# Wait for completion (polling)
result = client.executions.wait_for_completion(
    "exec_123",
    poll_interval=1.0,
    timeout=300.0
)

# Stream execution events (SSE)
for event in client.executions.stream("exec_123"):
    print(f"Event: {event['type']}")
    if event["type"] == "execution:completed":
        print(f"Outputs: {event.get('outputs')}")
        break

# Cancel execution
response = client.executions.cancel("exec_123")

Agents & Threads

# List agents
response = client.agents.list()

# Create a conversation thread
response = client.agents.create_thread("agent_123", metadata={"user_id": "user_456"})
thread_id = response["data"]["id"]

# Send a message
response = client.threads.send_message(thread_id, "Hello!")

# Stream the response
for event in client.threads.send_message_stream(thread_id, "Tell me a story"):
    if event["type"] == "message:token":
        print(event.get("token", ""), end="", flush=True)
    elif event["type"] == "message:completed":
        print("\n\nDone!")
        break

# Get message history
response = client.threads.list_messages(thread_id)

Knowledge Bases

# List knowledge bases
response = client.knowledge_bases.list()

# Semantic search
response = client.knowledge_bases.query(
    "kb_123",
    "How do I reset my password?",
    top_k=5
)

for result in response["data"]["results"]:
    print(f"[{result['similarity']:.3f}] {result['content']}")

Webhooks

# Create a webhook
response = client.webhooks.create(
    name="My Webhook",
    url="https://my-app.com/webhook",
    events=["execution.completed", "execution.failed"]
)

# Test webhook
response = client.webhooks.test("wh_123")
print(f"Response time: {response['data']['response_time_ms']}ms")

# Delete webhook
client.webhooks.delete("wh_123")

Error Handling

from flowmaestro import (
    FlowMaestroClient,
    FlowMaestroError,
    AuthenticationError,
    RateLimitError,
    NotFoundError
)

try:
    client.workflows.get("invalid-id")
except NotFoundError:
    print("Workflow not found")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except AuthenticationError:
    print("Invalid API key")
except FlowMaestroError as e:
    print(f"API error: {e.code} - {e.message}")

Type Hints

The SDK is fully typed and includes a py.typed marker for PEP 561 compliance:

from flowmaestro.types import Workflow, Execution, ExecutionStatus

Requirements

  • Python 3.9+
  • httpx
  • httpx-sse

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

flowmaestro-0.1.0.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

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

flowmaestro-0.1.0-py3-none-any.whl (21.7 kB view details)

Uploaded Python 3

File details

Details for the file flowmaestro-0.1.0.tar.gz.

File metadata

  • Download URL: flowmaestro-0.1.0.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for flowmaestro-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7d26f84ce31523ec154e340301234ea890363a229ef598d71b0263238ebb7097
MD5 e79e79e37ccb391485a6a67708e2e9c1
BLAKE2b-256 384f5ba6c10b2bd4fd609897249f0c8adabb78bc162afbf6bada3528d50dc05b

See more details on using hashes here.

File details

Details for the file flowmaestro-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flowmaestro-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for flowmaestro-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1a6acc385e57621e673d58721a0622ec961eb81dd4a963a9742b2ce63c8b55d9
MD5 8c08275dcebc7e9ccbdf92a5fb13b908
BLAKE2b-256 68873aac2b2a8896bba12272b3e20179502ef3d08344fba62e3f931c8f9a474f

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