Skip to main content

SteelEngine SDK - Execute workflows programmatically

Project description

SteelEngine Python SDK

The official Python SDK for SteelEngine, allowing you to execute workflows programmatically from your Python applications.

Installation

pip install steelengine-sdk

Quick Start

import os
from steelengine import SteelEngineClient

# Initialize the client
client = SteelEngineClient(
    api_key=os.getenv("STEELENGINE_API_KEY", "your-api-key-here"),
    base_url="https://steelengine.com"  # optional, defaults to https://steelengine.com
)

# Execute a workflow
try:
    result = client.execute_workflow("workflow-id")
    print("Workflow executed successfully:", result)
except Exception as error:
    print("Workflow execution failed:", error)

API Reference

SteelEngineClient

Constructor

SteelEngineClient(api_key: str, base_url: str = "https://steelengine.com")
  • api_key (str): Your SteelEngine API key
  • base_url (str, optional): Base URL for the SteelEngine API (defaults to https://steelengine.com)

Methods

execute_workflow(workflow_id, input=None, *, timeout=30.0, stream=None, selected_outputs=None, async_execution=None)

Execute a workflow with optional input data.

# With dict input (spread at root level of request body)
result = client.execute_workflow("workflow-id", {"message": "Hello, world!"})

# With primitive input (wrapped as { input: value })
result = client.execute_workflow("workflow-id", "NVDA")

# With options (keyword-only arguments)
result = client.execute_workflow("workflow-id", {"message": "Hello"}, timeout=60.0)

Parameters:

  • workflow_id (str): The ID of the workflow to execute
  • input (any, optional): Input data to pass to the workflow. Dicts are spread at the root level, primitives/lists are wrapped in { input: value }. File objects are automatically converted to base64.
  • timeout (float, keyword-only): Timeout in seconds (default: 30.0)
  • stream (bool, keyword-only): Enable streaming responses
  • selected_outputs (list, keyword-only): Block outputs to stream (e.g., ["agent1.content"])
  • async_execution (bool, keyword-only): Execute asynchronously and return execution ID

Returns: WorkflowExecutionResult or AsyncExecutionResult

get_workflow_status(workflow_id)

Get the status of a workflow (deployment status, etc.).

status = client.get_workflow_status("workflow-id")
print("Is deployed:", status.is_deployed)

Parameters:

  • workflow_id (str): The ID of the workflow

Returns: WorkflowStatus

validate_workflow(workflow_id)

Validate that a workflow is ready for execution.

is_ready = client.validate_workflow("workflow-id")
if is_ready:
    # Workflow is deployed and ready
    pass

Parameters:

  • workflow_id (str): The ID of the workflow

Returns: bool

execute_workflow_sync(workflow_id, input=None, *, timeout=30.0, stream=None, selected_outputs=None)

Execute a workflow synchronously (ensures non-async mode).

result = client.execute_workflow_sync("workflow-id", {"data": "some input"}, timeout=60.0)

Parameters:

  • workflow_id (str): The ID of the workflow to execute
  • input (any, optional): Input data to pass to the workflow
  • timeout (float, keyword-only): Timeout in seconds (default: 30.0)
  • stream (bool, keyword-only): Enable streaming responses
  • selected_outputs (list, keyword-only): Block outputs to stream (e.g., ["agent1.content"])

Returns: WorkflowExecutionResult

get_job_status(task_id)

Get the status of an async job.

status = client.get_job_status("task-id-from-async-execution")
print("Job status:", status)

Parameters:

  • task_id (str): The task ID returned from async execution

Returns: dict

execute_with_retry(workflow_id, input=None, *, timeout=30.0, stream=None, selected_outputs=None, async_execution=None, max_retries=3, initial_delay=1.0, max_delay=30.0, backoff_multiplier=2.0)

Execute a workflow with automatic retry on rate limit errors.

result = client.execute_with_retry(
    "workflow-id",
    {"message": "Hello"},
    timeout=30.0,
    max_retries=3,
    initial_delay=1.0,
    max_delay=30.0,
    backoff_multiplier=2.0
)

Parameters:

  • workflow_id (str): The ID of the workflow to execute
  • input (any, optional): Input data to pass to the workflow
  • timeout (float, keyword-only): Timeout in seconds (default: 30.0)
  • stream (bool, keyword-only): Enable streaming responses
  • selected_outputs (list, keyword-only): Block outputs to stream
  • async_execution (bool, keyword-only): Execute asynchronously
  • max_retries (int, keyword-only): Maximum retry attempts (default: 3)
  • initial_delay (float, keyword-only): Initial delay in seconds (default: 1.0)
  • max_delay (float, keyword-only): Maximum delay in seconds (default: 30.0)
  • backoff_multiplier (float, keyword-only): Backoff multiplier (default: 2.0)

Returns: WorkflowExecutionResult or AsyncExecutionResult

get_rate_limit_info()

Get current rate limit information from the last API response.

rate_info = client.get_rate_limit_info()
if rate_info:
    print("Remaining requests:", rate_info.remaining)

Returns: RateLimitInfo or None

get_usage_limits()

Get current usage limits and quota information.

limits = client.get_usage_limits()
print("Current usage:", limits.usage)

Returns: UsageLimits

set_api_key(api_key)

Update the API key.

client.set_api_key("new-api-key")
set_base_url(base_url)

Update the base URL.

client.set_base_url("https://my-custom-domain.com")
close()

Close the underlying HTTP session.

client.close()

Data Classes

WorkflowExecutionResult

@dataclass
class WorkflowExecutionResult:
    success: bool
    output: Optional[Any] = None
    error: Optional[str] = None
    logs: Optional[list] = None
    metadata: Optional[Dict[str, Any]] = None
    trace_spans: Optional[list] = None
    total_duration: Optional[float] = None

WorkflowStatus

@dataclass
class WorkflowStatus:
    is_deployed: bool
    deployed_at: Optional[str] = None
    needs_redeployment: bool = False

SteelEngineError

class SteelEngineError(Exception):
    def __init__(self, message: str, code: Optional[str] = None, status: Optional[int] = None):
        super().__init__(message)
        self.code = code
        self.status = status

AsyncExecutionResult

@dataclass
class AsyncExecutionResult:
    success: bool
    task_id: str
    status: str  # 'queued'
    created_at: str
    links: Dict[str, str]

RateLimitInfo

@dataclass
class RateLimitInfo:
    limit: int
    remaining: int
    reset: int
    retry_after: Optional[int] = None

UsageLimits

@dataclass
class UsageLimits:
    success: bool
    rate_limit: Dict[str, Any]
    usage: Dict[str, Any]

Examples

Basic Workflow Execution

import os
from steelengine import SteelEngineClient

client = SteelEngineClient(api_key=os.getenv("STEELENGINE_API_KEY"))

def run_workflow():
    try:
        # Check if workflow is ready
        is_ready = client.validate_workflow("my-workflow-id")
        if not is_ready:
            raise Exception("Workflow is not deployed or ready")

        # Execute the workflow
        result = client.execute_workflow(
            "my-workflow-id",
            {
                "message": "Process this data",
                "user_id": "12345"
            }
        )

        if result.success:
            print("Output:", result.output)
            print("Duration:", result.metadata.get("duration") if result.metadata else None)
        else:
            print("Workflow failed:", result.error)
            
    except Exception as error:
        print("Error:", error)

run_workflow()

Error Handling

from steelengine import SteelEngineClient, SteelEngineError
import os

client = SteelEngineClient(api_key=os.getenv("STEELENGINE_API_KEY"))

def execute_with_error_handling():
    try:
        result = client.execute_workflow("workflow-id")
        return result
    except SteelEngineError as error:
        if error.code == "UNAUTHORIZED":
            print("Invalid API key")
        elif error.code == "TIMEOUT":
            print("Workflow execution timed out")
        elif error.code == "USAGE_LIMIT_EXCEEDED":
            print("Usage limit exceeded")
        elif error.code == "INVALID_JSON":
            print("Invalid JSON in request body")
        else:
            print(f"Workflow error: {error}")
        raise
    except Exception as error:
        print(f"Unexpected error: {error}")
        raise

Context Manager Usage

from steelengine import SteelEngineClient
import os

# Using context manager to automatically close the session
with SteelEngineClient(api_key=os.getenv("STEELENGINE_API_KEY")) as client:
    result = client.execute_workflow("workflow-id")
    print("Result:", result)
# Session is automatically closed here

Environment Configuration

import os
from steelengine import SteelEngineClient

# Using environment variables
client = SteelEngineClient(
    api_key=os.getenv("STEELENGINE_API_KEY"),
    base_url=os.getenv("STEELENGINE_BASE_URL", "https://steelengine.com")
)

File Upload

File objects are automatically detected and converted to base64 format. Include them in your input under the field name matching your workflow's API trigger input format:

The SDK converts file objects to this format:

{
  'type': 'file',
  'data': 'data:mime/type;base64,base64data',
  'name': 'filename',
  'mime': 'mime/type'
}

Alternatively, you can manually provide files using the URL format:

{
  'type': 'url',
  'data': 'https://example.com/file.pdf',
  'name': 'file.pdf',
  'mime': 'application/pdf'
}
from steelengine import SteelEngineClient
import os

client = SteelEngineClient(api_key=os.getenv("STEELENGINE_API_KEY"))

# Upload a single file - include it under the field name from your API trigger
with open('document.pdf', 'rb') as f:
    result = client.execute_workflow(
        'workflow-id',
        {
            'documents': [f],  # Must match your workflow's "files" field name
            'instructions': 'Analyze this document'
        }
    )

# Upload multiple files
with open('doc1.pdf', 'rb') as f1, open('doc2.pdf', 'rb') as f2:
    result = client.execute_workflow(
        'workflow-id',
        {
            'attachments': [f1, f2],  # Must match your workflow's "files" field name
            'query': 'Compare these documents'
        }
    )

Batch Workflow Execution

from steelengine import SteelEngineClient
import os

client = SteelEngineClient(api_key=os.getenv("STEELENGINE_API_KEY"))

def execute_workflows_batch(workflow_data_pairs):
    """Execute multiple workflows with different input data."""
    results = []

    for workflow_id, workflow_input in workflow_data_pairs:
        try:
            # Validate workflow before execution
            if not client.validate_workflow(workflow_id):
                print(f"Skipping {workflow_id}: not deployed")
                continue

            result = client.execute_workflow(workflow_id, workflow_input)
            results.append({
                "workflow_id": workflow_id,
                "success": result.success,
                "output": result.output,
                "error": result.error
            })

        except Exception as error:
            results.append({
                "workflow_id": workflow_id,
                "success": False,
                "error": str(error)
            })

    return results

# Example usage
workflows = [
    ("workflow-1", {"type": "analysis", "data": "sample1"}),
    ("workflow-2", {"type": "processing", "data": "sample2"}),
]

results = execute_workflows_batch(workflows)
for result in results:
    print(f"Workflow {result['workflow_id']}: {'Success' if result['success'] else 'Failed'}")

Getting Your API Key

  1. Log in to your SteelEngine account
  2. Navigate to your workflow
  3. Click on "Deploy" to deploy your workflow
  4. Select or create an API key during the deployment process
  5. Copy the API key to use in your application

Development

Running Tests

To run the tests locally:

  1. Clone the repository and navigate to the Python SDK directory:

    cd packages/python-sdk
    
  2. Create and activate a virtual environment:

    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install the package in development mode with test dependencies:

    pip install -e ".[dev]"
    
  4. Run the tests:

    pytest tests/ -v
    

Code Quality

Run code quality checks:

# Code formatting
black steelengine/

# Linting
flake8 steelengine/ --max-line-length=100

# Type checking
mypy steelengine/

# Import sorting
isort steelengine/

Requirements

  • Python 3.8+
  • requests >= 2.25.0

License

Apache-2.0

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

steelengine_sdk-0.2.1.tar.gz (17.5 kB view details)

Uploaded Source

Built Distribution

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

steelengine_sdk-0.2.1-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file steelengine_sdk-0.2.1.tar.gz.

File metadata

  • Download URL: steelengine_sdk-0.2.1.tar.gz
  • Upload date:
  • Size: 17.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for steelengine_sdk-0.2.1.tar.gz
Algorithm Hash digest
SHA256 8437bd40acd876405e7eb1b93addc0eb4e8582fd7d499a3d0ae46c46817644b2
MD5 727c072534c2387bcfc2fcfb6232bce0
BLAKE2b-256 fc2835990b44fcc1d15c3b6944424fd2df40348256a0e30aab495f5477455e2f

See more details on using hashes here.

File details

Details for the file steelengine_sdk-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for steelengine_sdk-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a31587c6a23503c52ceb61fd4656ee96bd586d0c5730f8d8ee01c1c4914b3982
MD5 65f80c1f399cf8753a81f29bcdf7796f
BLAKE2b-256 b4679d4880d98c50634d5b92e166aac8df2a1501eb5007a099466c1bab59366a

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