Plato Python SDK

The Plato Python SDK provides a powerful interface for browser automation and task execution. It enables you to create and manage browser environments, execute tasks, and handle automation workflows efficiently.

Installation

pip install plato-sdk
# or install using uv
uv add plato-sdk

Quick Start

Here’s a basic example of how to use the Plato SDK:

import asyncio
import os
from plato import Plato, PlatoTask

async def run_task(client: Plato, task: PlatoTask):
    # Create and initialize environment
    env = await client.make_environment(task.env_id, open_page_on_start=False)
    await env.wait_for_ready()
    await env.reset(task)

    # Get CDP URL for browser connection
    cdp_url = await env.get_cdp_url()

    # Get live view URL for monitoring
    live_view_url = await env.get_live_view_url()
    print(f"Live view URL: {live_view_url}")

    try:
        # Connect agent and execute task
        await YourAgent.run(cdp_url, prompt)
        result = await env.evaluate()
        print(f"Evaluation result: {result}")
    except Exception as e:
        print(f"Error: {e}")
    finally:
        await env.close()

async def main():
    client = Plato(api_key=os.environ.get("PLATO_API_KEY"))
    tasks = await client.load_tasks("doordash")
    for task in tasks:
        await run_task(client, task)

if __name__ == "__main__":
    asyncio.run(main())

Core Components

Plato Client

The main entry point for interacting with the Plato platform:

from plato import Plato

client = Plato(
    api_key="your_api_key",  # Or use PLATO_API_KEY environment variable
    base_url="https://plato.so/api"  # Optional
)

PlatoTask

Defines the structure of an automation task:

class PlatoTask:
    name: str        # Task identifier
    prompt: str      # Task instructions
    start_url: str   # Starting URL
    env_id: str      # Environment identifier

PlatoEnvironment

Manages browser environments and task execution:

# Create environment
env = await client.make_environment(
    env_id="your_env_id",
    open_page_on_start=False
)

# Initialize and reset
await env.wait_for_ready()
await env.reset(task)

# Get connection URLs
cdp_url = await env.get_cdp_url()
live_view_url = await env.get_live_view_url()

# Cleanup
await env.close()

Task Execution

Loading Tasks

# Load predefined tasks
tasks = await client.load_tasks("doordash")

# Create custom task
custom_task = PlatoTask(
    name="custom_order",
    prompt="Order a large pizza with pepperoni",
    start_url="https://doordash.com",
    env_id="doordash"
)

Environment Management

# Create environment with options
env = await client.make_environment(
    env_id="doordash",
    open_page_on_start=False,
    # Additional options as needed
)

# Wait for environment readiness
await env.wait_for_ready()

# Reset environment with task
await env.reset(task)

Browser Control

# Get CDP URL for browser automation
cdp_url = await env.get_cdp_url()

# Get live view URL for monitoring
live_view_url = await env.get_live_view_url()

# Evaluate task completion
result = await env.evaluate()

Environment Variables

Required environment variables:

# Required
PLATO_API_KEY=your_plato_api_key

# Optional - Based on your AI provider
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key

Available Task Sets

The SDK includes several pre-configured task sets:

  • DoorDash: Food ordering automation
  • EspoCRM: CRM automation
  • Roundcube: Email client automation
  • Mattermost: Team collaboration

Error Handling

try:
    env = await client.make_environment(task.env_id)
    await env.wait_for_ready()
    await env.reset(task)
    
    # Execute task
    result = await env.evaluate()
    
except Exception as e:
    print(f"Error during task execution: {e}")
finally:
    await env.close()

Best Practices

  1. Resource Management

    • Always use try/finally blocks to ensure proper cleanup
    • Close environments after use
    • Handle exceptions appropriately
  2. Environment Setup

    • Set environment variables securely
    • Never commit API keys to version control
    • Use appropriate timeouts for operations
  3. Task Design

    • Create clear, specific task prompts
    • Include necessary validation steps
    • Handle edge cases and errors

Examples

For complete examples and use cases, visit our examples repository.

License

This SDK is available under the MIT License.