Skip to main content

Production-quality Python SDK for FounderX-AI Orchestration API with sync/async support, automatic retries, and comprehensive error handling

Project description

FounderX-AI Orchestration SDK for Python

PyPI version Python License: MIT

Production-quality Python SDK for the FounderX-AI Orchestration API with both synchronous and asynchronous support.

Note: Currently published to Test PyPI. Production PyPI release coming soon!

Features

  • Sync & Async Support: Use OrchestrationClient for sync or AsyncOrchestrationClient for async
  • Comprehensive Error Handling: Custom exceptions for every error type
  • Automatic Retries: Exponential backoff for rate limits and server errors
  • Type Hints: Full type annotations throughout
  • Pagination Helpers: Automatic pagination with iterator support
  • Streaming: Real-time execution streaming via SSE
  • Full API Coverage: All endpoints including auth, execution, artifacts, webhooks, marketplace, analytics, settings
  • Context Managers: Proper resource cleanup with with statements

Installation

From Test PyPI (Current)

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple rc-orchestration-sdk

From Production PyPI (Coming Soon)

pip install rc-orchestration-sdk

Quick Start

Synchronous Client

from rc_orchestration_sdk import OrchestrationClient

# Initialize client
client = OrchestrationClient(base_url="https://api.example.com")

# Login
client.login("username", "password")

# Start execution
execution = client.execute(
    template_id="my-template",
    parameters={"env": "production"},
    workspace="default"
)

print(f"Execution started: {execution.execution_id}")

# List artifacts
artifacts = client.list_artifacts(execution_id=execution.execution_id)
for artifact in artifacts.items:
    print(f"Artifact: {artifact.name} ({artifact.size} bytes)")

# Download artifact
client.download_artifact(
    artifact_id="artifact-123",
    output_path="/tmp/result.json"
)

Asynchronous Client

import asyncio
from rc_orchestration_sdk import AsyncOrchestrationClient

async def main():
    # Use context manager for automatic cleanup
    async with AsyncOrchestrationClient(base_url="https://api.example.com") as client:
        # Login
        await client.login("username", "password")

        # Start execution
        execution = await client.execute(
            template_id="my-template",
            parameters={"env": "production"}
        )

        # Stream execution updates in real-time
        async for event in client.stream_execution(execution.execution_id):
            print(f"Event: {event['type']} - {event['data']}")

        # Iterate over all artifacts with automatic pagination
        async for artifact in client.iter_all_artifacts(execution_id=execution.execution_id):
            print(f"Artifact: {artifact.name}")

asyncio.run(main())

Authentication

Username/Password

client = OrchestrationClient(base_url="https://api.example.com")
client.login("username", "password")

Access Token

client = OrchestrationClient(
    base_url="https://api.example.com",
    access_token="your-access-token"
)

API Key (Public API)

client = OrchestrationClient(
    base_url="https://api.example.com",
    api_key="your-api-key"
)

# Use api_key for public endpoints
status = client.status(use_api_key=True)

Environment Variables

export ORCH_BASE_URL="https://api.example.com/api/v1"
export ORCH_ACCESS_TOKEN="your-access-token"
export PUBLIC_API_KEY="your-api-key"
# Client automatically picks up environment variables
client = OrchestrationClient()

Core Functionality

Execution Management

# Start execution
execution = client.execute(
    template_id="my-template",
    parameters={"key": "value"},
    workspace="default",
    priority=5,
    timeout=3600,
    tags=["production", "critical"]
)

# Get execution status
execution = client.get_execution("execution-123")
print(f"Status: {execution.status}")
print(f"Result: {execution.result}")

# List executions
executions = client.list_executions(
    workspace="default",
    status="completed",
    limit=50
)

# Cancel execution
client.cancel_execution("execution-123")

# Stream execution updates
for event in client.stream_execution("execution-123"):
    print(event)

Artifact Management

# List artifacts
artifacts = client.list_artifacts(
    execution_id="execution-123",
    workspace="default",
    limit=50
)

# Get artifact metadata
artifact = client.get_artifact("artifact-123")

# Download artifact to file
client.download_artifact("artifact-123", "/tmp/output.json")

# Download artifact to memory
content = client.download_artifact_content("artifact-123")

# Upload artifact
with open("/tmp/data.json", "rb") as f:
    artifact = client.upload_artifact(
        execution_id="execution-123",
        name="data.json",
        file=f,
        artifact_type="json",
        metadata={"version": "1.0"}
    )

# Sign artifact with GPG
signed_artifact = client.sign_artifact("artifact-123")
print(f"Signature: {signed_artifact.signature}")

Webhooks

# List webhooks
webhooks = client.list_webhooks()

# Create webhook
webhook = client.create_webhook(
    url="https://example.com/webhook",
    events=["execution.completed", "execution.failed"],
    secret="webhook-secret",
    metadata={"team": "engineering"}
)

# Delete webhook
client.delete_webhook("webhook-123")

# Rotate webhook secret
webhook = client.rotate_webhook_secret("webhook-123")
print(f"New secret: {webhook.secret}")

Marketplace

# List marketplace templates
templates = client.list_marketplace_templates(
    category="backend",
    search="rest api",
    limit=20
)

# Get template details
template = client.get_marketplace_template("template-123")
print(f"Name: {template.name}")
print(f"Rating: {template.rating}")
print(f"Downloads: {template.downloads}")

Analytics & Settings

# Get usage statistics
stats = client.get_usage_stats(
    workspace="default",
    start_date="2025-01-01",
    end_date="2025-01-31"
)
print(f"Total executions: {stats.total_executions}")
print(f"Total cost: ${stats.total_cost}")

# Get settings
settings = client.get_settings(workspace="default")

# Update settings
settings = client.update_settings(
    workspace="default",
    settings={
        "default_provider": "anthropic",
        "default_model": "claude-3-5-sonnet-20241022"
    }
)

Advanced Features

Automatic Pagination

# Iterate over all executions automatically
for execution in client.iter_all_executions(workspace="default"):
    print(f"Execution: {execution.execution_id}")

# Iterate over all artifacts
for artifact in client.iter_all_artifacts(execution_id="execution-123"):
    print(f"Artifact: {artifact.name}")

Context Manager

# Automatic session cleanup
with OrchestrationClient(base_url="https://api.example.com") as client:
    client.login("username", "password")
    executions = client.list_executions()
    # Session automatically closed on exit

Custom Configuration

client = OrchestrationClient(
    base_url="https://api.example.com",
    timeout=60,              # Request timeout in seconds
    max_retries=5,           # Maximum retry attempts
    backoff_factor=1.0       # Exponential backoff factor
)

Error Handling

from rc_orchestration_sdk import (
    AuthenticationError,
    AuthorizationError,
    NotFoundError,
    RateLimitError,
    ValidationError,
    ServerError,
    NetworkError,
    TimeoutError
)

try:
    client.login("username", "wrong-password")
except AuthenticationError as e:
    print(f"Auth failed: {e.message}")
    print(f"Status code: {e.status_code}")

try:
    execution = client.execute(template_id="invalid")
except ValidationError as e:
    print(f"Validation failed: {e.message}")
    print(f"Response: {e.response}")

try:
    artifact = client.get_artifact("nonexistent")
except NotFoundError as e:
    print(f"Not found: {e.message}")

try:
    # Too many requests
    for i in range(1000):
        client.status()
except RateLimitError as e:
    print(f"Rate limited: {e.message}")
    print(f"Retry after: {e.retry_after} seconds")

Requirements

  • Python 3.9+
  • requests >= 2.31.0
  • httpx >= 0.25.0 (for async client)

Version History

  • v1.0.0 (2025-01-10): Initial production release
    • Synchronous and asynchronous clients
    • Full API coverage
    • Comprehensive error handling
    • Automatic retries and pagination
    • Type hints throughout

License

MIT License - see LICENSE file for details

Support

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

rc_orchestration_sdk-1.1.0.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

rc_orchestration_sdk-1.1.0-py3-none-any.whl (19.7 kB view details)

Uploaded Python 3

File details

Details for the file rc_orchestration_sdk-1.1.0.tar.gz.

File metadata

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

File hashes

Hashes for rc_orchestration_sdk-1.1.0.tar.gz
Algorithm Hash digest
SHA256 74314a3ceaaf1b985b15a0c4c369ceb1152fc7103d0b195325a191047131b104
MD5 36fc79460fcd9d0ef423aafa09ba840d
BLAKE2b-256 62fbc22ec4ddaef9d25b7fb6427b90b3c8051700a30b2c0f9f43c91e7d631877

See more details on using hashes here.

File details

Details for the file rc_orchestration_sdk-1.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rc_orchestration_sdk-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85a83153342f9efa768fb1cdd3c398b0281079b218883001fad570507e92b752
MD5 318f4ad7131690057c7c20b21adf4a2e
BLAKE2b-256 7ed97d5234747c551a4985b0f7048ef8dae6a11c626c79073b4d92ba163ad93f

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