Skip to main content

Python SDK for the Plato API

Project description

Plato Python SDK

Python SDK for the Plato API v2.

Installation

pip install plato-sdk

Quick Start

from plato.v2 import Client, Env

# Synchronous usage
with Client() as client:
    # Create a session with an environment
    with client.session(envs=[Env.artifact("espocrm")]) as session:
        # Batch operations on all environments
        session.reset()
        state = session.get_state()

        # Per-environment operations
        for env in session.envs:
            result = env.execute("ls -la")
            print(result)

Environment Configuration

The SDK provides three modes for creating environments using the Env helper, which returns EnvConfig objects:

Mode 1: Simulator with Tag (Default)

Start from a snapshotted artifact using "simulator:tag" format:

from plato.v2 import Client, Env

with Client() as client:
    # Use default :prod-latest tag
    session = client.session(envs=[Env.artifact("espocrm")])
    # Equivalent to: Env.artifact("espocrm:prod-latest")

    # Use custom tag
    session = client.session(envs=[Env.artifact("espocrm:staging")])

    # With custom alias
    session = client.session(envs=[Env.artifact("espocrm", alias="crm")])

Mode 2: Explicit Artifact ID

Start from a specific artifact snapshot using its ID:

from plato.v2 import Client, Env

with Client() as client:
    # Use explicit artifact ID
    session = client.session(envs=[
        Env.artifact(artifact_id="artifact-123", alias="my-env")
    ])

Mode 3: Custom VM Resources

Create a blank VM with custom CPU, memory, and disk configuration:

from plato.v2 import Client, Env, SimConfigCompute

with Client() as client:
    # Create blank VM with custom resources
    session = client.session(envs=[
        Env.resource(
            "redis",
            SimConfigCompute(cpus=4, memory=8192, disk=20000),
            alias="cache"
        )
    ])

Multiple Environments

from plato.v2 import Client, Env, SimConfigCompute

with Client() as client:
    # Mix artifact and resource-based environments
    envs = [
        Env.artifact("espocrm", alias="crm"),
        Env.artifact("wordpress:staging", alias="blog"),
        Env.resource("redis", SimConfigCompute(cpus=2, memory=4096), alias="cache"),
    ]

    with client.session.from_envs(envs) as session:
        # Access environments by alias
        crm = session.get_env("crm")
        blog = session.get_env("blog")
        cache = session.get_env("cache")

        if crm:
            crm.execute("echo 'Hello CRM'")
        if blog:
            blog.execute("echo 'Hello Blog'")

Create Session from Task

from plato.v2 import Client

with Client() as client:
    # Create session from a task ID
    session = client.from_task(task_id=123)

Async Usage

import asyncio
from plato.v2 import AsyncClient, Env

async def main():
    async with AsyncClient() as client:
        async with await client.session(envs=[Env.artifact("espocrm")]) as session:
            await session.reset()
            state = await session.get_state()

            for env in session.envs:
                result = await env.execute("ls -la")
                print(result)

asyncio.run(main())

Session Operations

from plato.v2 import Client, Env

with Client() as client:
    with client.session(envs=[Env.artifact("espocrm")]) as session:
        # Reset all environments
        session.reset()

        # Get state from all environments
        state = session.get_state()

        # Execute command on all environments
        results = session.execute("ls -la", timeout=30)

        # Create snapshot of all environments
        snapshots = session.snapshot()

        # Evaluate session
        evaluation = session.evaluate()

        # Send heartbeat (automatically done when using context manager)
        session.heartbeat()

Per-Environment Operations

from plato.v2 import Client, Env

with Client() as client:
    with client.session(envs=[Env.artifact("espocrm", alias="crm")]) as session:
        # Get specific environment
        env = session.get_env("crm")

        if env:
            # Execute command
            result = env.execute("pwd")
            print(result.stdout)

            # Reset environment
            env.reset()

            # Create snapshot
            snapshot = env.snapshot()

            # Get state
            state = env.get_state()

            # Close environment
            env.close()

Configuration

Set your API key via environment variable:

export PLATO_API_KEY=your-api-key

Or pass it directly:

from plato.v2 import Client

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

Configure custom base URL:

export PLATO_BASE_URL=https://custom.plato.so

Or:

client = Client(base_url="https://custom.plato.so")

License

MIT

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plato_sdk_v2-2.0.1.tar.gz (338.5 kB view details)

Uploaded Source

Built Distribution

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

plato_sdk_v2-2.0.1-py3-none-any.whl (463.9 kB view details)

Uploaded Python 3

File details

Details for the file plato_sdk_v2-2.0.1.tar.gz.

File metadata

  • Download URL: plato_sdk_v2-2.0.1.tar.gz
  • Upload date:
  • Size: 338.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.15

File hashes

Hashes for plato_sdk_v2-2.0.1.tar.gz
Algorithm Hash digest
SHA256 6e6c5be44fc64af7960bbaf2d1a74a5e0c81845dae5bd195df93933d3cce9ac2
MD5 00a82c11069d4781976e8e513f4ba5e8
BLAKE2b-256 f07b6742b2ff1285038885e3d95037c9e0dfab9cd199efecccdc38d43bb2d12e

See more details on using hashes here.

File details

Details for the file plato_sdk_v2-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for plato_sdk_v2-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8537e38f94805cf53f527e32958089c69ce61c9f603087b2357f6f27d1e532e9
MD5 6cf46c2993b3d3defc71a701d7a57ad2
BLAKE2b-256 016b2d35ed272095335d45986b11dcf3eec87348e834690f537f4cb04537b364

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