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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lindoai-1.0.6.tar.gz.
File metadata
- Download URL: lindoai-1.0.6.tar.gz
- Upload date:
- Size: 32.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
abc31309ed9954a199eb404d89993ff8bf407bb3526b2ffbfa9668709ff04554
|
|
| MD5 |
9cac8e56a205aa9e9c606be4287ae450
|
|
| BLAKE2b-256 |
6bc5b9542ac957f19bceb6be6cc6b4bdc9fb02215d6600431689e63474388a89
|
File details
Details for the file lindoai-1.0.6-py3-none-any.whl.
File metadata
- Download URL: lindoai-1.0.6-py3-none-any.whl
- Upload date:
- Size: 34.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ac1b05d43286b3d22865a6c5b24690f32027e3559800893e87b3eb1a5152641
|
|
| MD5 |
3ad95719ed5008f03adff1a7763a8ab1
|
|
| BLAKE2b-256 |
4e34e9b9e711793b7e4f6628dd1ff711fb798ea879559568ed271e076755c797
|