Plato Python SDK (v2)

2.62.4 · active · verified Thu Apr 16

The Plato Python SDK (v2) provides a powerful interface for browser automation and task execution, enabling developers to efficiently create and manage browser environments and execute tasks. It is currently at version 2.62.4 and is under active development, with frequent updates indicated by recent changelogs.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `AsyncPlato` client, create and manage a session with a simulated environment, execute commands, retrieve state, and ensure proper cleanup. It relies on the `PLATO_API_KEY` environment variable for authentication.

import asyncio
import os
from plato.v2 import AsyncPlato, Env

async def main():
    # Ensure PLATO_API_KEY environment variable is set
    # export PLATO_API_KEY="your_api_key_here"
    if not os.environ.get("PLATO_API_KEY"):
        print("Error: PLATO_API_KEY environment variable not set.")
        print("Please generate your API key from the Plato dashboard and set it.")
        return

    # Initialize the client
    plato = AsyncPlato()

    # Create a session with an example environment (e.g., 'espocrm' simulator)
    session = await plato.sessions.create(
        envs=[Env.simulator("espocrm")]
    )

    try:
        # Reset the environment to its initial state
        await session.reset()

        # Get the public URL to access the application (if applicable)
        urls = await session.get_public_url()
        print(f"Access your environment at: {urls}")

        # Execute a command within the environment
        result = await session.execute("whoami")
        print(f"Running as: {result}")

        # Get the current state of the environment
        state = await session.get_state()
        print(f"State: {state}")

    except Exception as e:
        print(f"An error occurred: {e}")
    finally:
        # Always clean up and close the session
        await session.close()
        await plato.close()

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

view raw JSON →