Skip to main content

Python SDK for the Lindo API

Project description

lindo-sdk

Python SDK for the Lindo API. Provides both synchronous and asynchronous clients for interacting with AI agents, workflows, workspace management, and analytics.

Installation

pip install lindo-sdk

Requirements

  • Python 3.8 or higher
  • httpx

Quick Start

Synchronous Client

from lindo_sdk import LindoClient

client = LindoClient(api_key="your-api-key")

# Run an agent
result = client.agents.run(
    agent_id="my-agent",
    input={"prompt": "Hello!"}
)

# Start a workflow
workflow = client.workflows.start(
    workflow_name="publish-page",
    params={"page_id": "page-123"}
)

# Get workspace credits
credits = client.workspace.get_credits()

# Get analytics
analytics = client.analytics.get_workspace(
    from_date="2024-01-01",
    to_date="2024-01-31"
)

# Close the client when done
client.close()

Using Context Manager

from lindo_sdk import LindoClient

with LindoClient(api_key="your-api-key") as client:
    result = client.agents.run(
        agent_id="my-agent",
        input={"prompt": "Hello!"}
    )

Asynchronous Client

import asyncio
from lindo_sdk import AsyncLindoClient

async def main():
    async with AsyncLindoClient(api_key="your-api-key") as client:
        # Run an agent
        result = await client.agents.run(
            agent_id="my-agent",
            input={"prompt": "Hello!"}
        )
        
        # Start a workflow
        workflow = await client.workflows.start(
            workflow_name="publish-page",
            params={"page_id": "page-123"}
        )
        
        # Get workspace credits
        credits = await client.workspace.get_credits()

asyncio.run(main())

Configuration

client = LindoClient(
    api_key="your-api-key",           # Required
    base_url="https://api.lindo.ai",  # Optional, defaults to https://api.lindo.ai
    timeout=30.0,                      # Optional, defaults to 30.0 seconds
)

API Reference

Agents

Run AI agents with custom inputs.

# Run an agent
result = client.agents.run(
    agent_id="my-agent",
    input={"prompt": "Hello!"},
    stream=False  # Optional: enable streaming
)

print(result.success)       # bool
print(result.output)        # Agent output
print(result.credits_used)  # Credits consumed

Workflows

Manage long-running workflows.

# Start a workflow
workflow = client.workflows.start(
    workflow_name="publish-page",
    params={"page_id": "page-123"}
)
print(workflow.instance_id)  # Workflow instance ID

# Start multiple workflows in batch
batch = client.workflows.batch_start(
    workflow_name="publish-page",
    items=[
        {"params": {"page_id": "page-1"}},
        {"params": {"page_id": "page-2"}},
    ]
)

# Get workflow status
status = client.workflows.get_status("instance-123")
print(status.status)  # 'queued', 'running', 'paused', 'completed', 'failed', 'terminated'

# Pause a workflow
client.workflows.pause("instance-123")

# Resume a workflow
client.workflows.resume("instance-123")

# Terminate a workflow
client.workflows.terminate("instance-123")

Workspace

Manage workspace resources.

# Get credit balance
credits = client.workspace.get_credits()
print(credits.balance)     # Current balance
print(credits.allocated)   # Total allocated
print(credits.used)        # Total used

Analytics

Access workspace and website analytics.

# Get workspace analytics
workspace_analytics = client.analytics.get_workspace(
    from_date="2024-01-01",  # Optional
    to_date="2024-01-31"     # Optional
)
print(workspace_analytics.total_views)
print(workspace_analytics.unique_visitors)

# Get website analytics
website_analytics = client.analytics.get_website(
    from_date="2024-01-01",
    to_date="2024-01-31"
)
print(website_analytics.top_pages)

Error Handling

The SDK provides custom exception classes for common error scenarios:

from lindo_sdk import (
    LindoClient,
    AuthenticationError,
    RateLimitError,
    NotFoundError,
    ValidationError,
    ServerError,
)

try:
    result = client.agents.run(
        agent_id="my-agent",
        input={}
    )
except AuthenticationError:
    # Invalid or expired API key (401)
    print("Please check your API key")
except RateLimitError as e:
    # Too many requests (429)
    print(f"Rate limited. Retry after {e.retry_after} seconds")
except NotFoundError:
    # Resource not found (404)
    print("Agent not found")
except ValidationError as e:
    # Invalid request (400)
    print(f"Validation errors: {e.errors}")
except ServerError:
    # Server error (5xx)
    print("Server error, please try again later")

Exception Classes

Exception HTTP Status Description
AuthenticationError 401 Invalid or expired API key
ForbiddenError 403 Insufficient permissions
NotFoundError 404 Resource not found
ValidationError 400 Invalid request parameters
RateLimitError 429 Too many requests
ServerError 5xx Internal server error
NetworkError - Network connection failed
TimeoutError - Request timed out

Types

The SDK uses dataclasses with type hints for all request and response types:

from lindo_sdk import (
    # Agent types
    AgentRunRequest,
    AgentRunResponse,
    
    # Workflow types
    WorkflowStartRequest,
    WorkflowStartResponse,
    WorkflowBatchStartRequest,
    WorkflowBatchStartResponse,
    WorkflowStatus,
    WorkflowActionResponse,
    
    # Workspace types
    WorkspaceCredits,
    
    # Analytics types
    AnalyticsQuery,
    WorkspaceAnalytics,
    WebsiteAnalytics,
)

Serialization

All dataclasses support to_dict() and from_dict() methods:

from lindo_sdk import AgentRunRequest

# Create from dict
request = AgentRunRequest.from_dict({
    "agent_id": "my-agent",
    "input": {"prompt": "Hello!"}
})

# Convert to dict
data = request.to_dict()

Development

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run type checking
mypy lindo_sdk

# Run linting
ruff check lindo_sdk

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

lindoai-1.0.3.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

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

lindoai-1.0.3-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

Details for the file lindoai-1.0.3.tar.gz.

File metadata

  • Download URL: lindoai-1.0.3.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for lindoai-1.0.3.tar.gz
Algorithm Hash digest
SHA256 c00c173249acab4ef22c82833c41a5fd68dbc4fd133a4008390ed1529a6ed1c2
MD5 e4ad708b506645dc2f4a17c2a8b6b2c5
BLAKE2b-256 ab67d3a6809574ed97e99e9bd551ec16a2b5bcce06ec54a8e04bbedb71283b59

See more details on using hashes here.

File details

Details for the file lindoai-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: lindoai-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 32.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for lindoai-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 b6fc886a92e7f1fc5349aff569a15be540414138d2371a3f7eef4a04123a1710
MD5 5ecb6dd7da466a6868833178e97316cc
BLAKE2b-256 8e0e025ce8860f30d121b55ee522b4e00c3145650926829d14ca440c9f91c3c7

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