{"id":8430,"library":"plato-sdk-v2","title":"Plato Python SDK (v2)","description":"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.","status":"active","version":"2.62.4","language":"en","source_language":"en","source_url":"https://plato.so/","tags":["automation","browser automation","task execution","api client","sdk"],"install":[{"cmd":"pip install plato-sdk-v2","lang":"bash","label":"Install with pip"},{"cmd":"uv add plato-sdk-v2","lang":"bash","label":"Install with uv"}],"dependencies":[{"reason":"Requires Python versions 3.10 up to (but not including) 3.14.","package":"Python","optional":false}],"imports":[{"note":"The v2 SDK introduces a new API under `plato.v2`, replacing the `Plato` client and `PlatoTask` from previous versions.","wrong":"from plato import Plato, PlatoTask","symbol":"AsyncPlato, Env","correct":"from plato.v2 import AsyncPlato, Env"}],"quickstart":{"code":"import asyncio\nimport os\nfrom plato.v2 import AsyncPlato, Env\n\nasync def main():\n    # Ensure PLATO_API_KEY environment variable is set\n    # export PLATO_API_KEY=\"your_api_key_here\"\n    if not os.environ.get(\"PLATO_API_KEY\"):\n        print(\"Error: PLATO_API_KEY environment variable not set.\")\n        print(\"Please generate your API key from the Plato dashboard and set it.\")\n        return\n\n    # Initialize the client\n    plato = AsyncPlato()\n\n    # Create a session with an example environment (e.g., 'espocrm' simulator)\n    session = await plato.sessions.create(\n        envs=[Env.simulator(\"espocrm\")]\n    )\n\n    try:\n        # Reset the environment to its initial state\n        await session.reset()\n\n        # Get the public URL to access the application (if applicable)\n        urls = await session.get_public_url()\n        print(f\"Access your environment at: {urls}\")\n\n        # Execute a command within the environment\n        result = await session.execute(\"whoami\")\n        print(f\"Running as: {result}\")\n\n        # Get the current state of the environment\n        state = await session.get_state()\n        print(f\"State: {state}\")\n\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n    finally:\n        # Always clean up and close the session\n        await session.close()\n        await plato.close()\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n","lang":"python","description":"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."},"warnings":[{"fix":"Update imports from `from plato import ...` to `from plato.v2 import ...`. Refactor client and environment management to use `AsyncPlato` and `session` objects as per the v2 documentation.","message":"The SDK v2 introduces significant API changes, moving from direct `Plato` and `PlatoTask` objects to `AsyncPlato` for client interaction and `sessions` for environment management. Code written for SDK v1.x will not be compatible with v2 without modifications.","severity":"breaking","affected_versions":"All versions migrating from plato-sdk (v1.x) to plato-sdk-v2 (v2.x)"},{"fix":"Set the `PLATO_API_KEY` environment variable. The `AsyncPlato` client will automatically pick it up. If explicit passing is required (e.g., for multiple keys), ensure secure handling.","message":"API keys should be managed securely, preferably via the `PLATO_API_KEY` environment variable. Directly embedding API keys in code is discouraged for security reasons.","severity":"gotcha","affected_versions":"All"},{"fix":"Always wrap your session and client usage in `try...finally` blocks to guarantee that `await session.close()` and `await plato.close()` are called, even if errors occur.","message":"Browser environments and sessions must be explicitly closed using `await session.close()` and `await plato.close()` within a `try...finally` block to prevent resource leaks and ensure proper cleanup.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Set the `PLATO_API_KEY` environment variable in your shell (e.g., `export PLATO_API_KEY=\"your_api_key_here\"` on Linux/macOS or `SET PLATO_API_KEY=your_api_key_here` on Windows) or pass it directly when initializing `AsyncPlato` (e.g., `AsyncPlato(api_key=\"...\")`).","cause":"The Plato SDK requires an API key for authentication, which is typically read from the `PLATO_API_KEY` environment variable.","error":"Error: PLATO_API_KEY environment variable not set."},{"fix":"Verify your internet connection. Double-check that your `PLATO_API_KEY` is correct and has the necessary permissions for the requested operations by checking your Plato dashboard.","cause":"Problems creating or connecting to a session can stem from network connectivity issues or incorrect/insufficient permissions associated with the provided API key.","error":"Session not starting / connection issues"},{"fix":"Update your import statements to use `from plato.v2 import AsyncPlato, Env` (or other v2-specific symbols) and adjust your code to the new v2 API structure.","cause":"This typically occurs when trying to use the older SDK v1 import patterns with `plato-sdk-v2`, which has moved core components to the `plato.v2` submodule.","error":"AttributeError: module 'plato' has no attribute 'Plato' or ImportError: cannot import name 'Plato' from 'plato'"}]}