Pig LogoPig Docs
SDK Reference/Python

Machines

The API to manage your machines.

Machine Management

The machines module provides methods to access both local and remote machines running Piglet.

Local Machine

To connect to a Piglet running on your local machine:

from pig import Client
client = Client()
 
# Get your local machine
machine = client.machines.local()

This connects to the Piglet server running on localhost (typically on port 3000).

Remote Machines

To connect to a remote machine that has been registered with Pig's control plane:

from pig import Client
client = Client()
 
# Get a remote machine by ID
machine = client.machines.get("M-6HNGAXR-NT0B3VA-P33Q0R2")

You'll need the machine ID, which you can find using the Pig CLI:

# List all machines
pig ls
 
# Example output:
ID                         state    Created
-------------------------  -------  ----------------
M-6HNGAXR-NT0B3VA-P33Q0R2  RUNNING  2025-02-10 23:31

Working with Machines

Once you have a machine reference, you can create a connection to send commands:

# Create a connection to the machine
with machine.connect() as conn:
    # Now you can send commands to the machine
    conn.type("Hello World")
    conn.key("super")
    # See the Connections documentation for more details

Connections provide the interface for interacting with the machine, including keyboard input, mouse control, and screen capture.

On this page