analitics

Pages

Friday, April 11, 2025

Python 3.13.0rc1 : pig for AI-powered automation.

Pig is an API for AI-powered automation of Windows desktop applications and workflows. It allows AI agents to remotely navigate user interfaces and interact with software on Windows computers, even for applications without public APIs. Organizations might use Pig to automate complex, repetitive tasks involving legacy enterprise software, overcome limitations of traditional robotic process automation tools, and reduce the need for manual data handling by human workers.
Follow the install from the official website.
pip install pig-python
Collecting pig-python
...
Successfully installed aiohttp-retry-2.9.1 click-8.1.8 iso8601-2.1.0 pig-python-0.1.2 simple-term-menu-1.6.6 tabulate-0.9.0
From the API Keys url get the key and run a server:
piglet join --secret the_API_key
Display dimensions: 1280x720
Local server running at http://localhost:3000
Connected to control server
The local machine can be found on this webpage.
I go to machine chat and I ask to create a source script in python for test the artificial intelligence.
It looks like you're encountering an error with the Pig API. The error message indicates that the API key hasn't been set properly. To resolve this issue, you need to set the PIG_SECRET_KEY environment variable or pass the API key directly to the Client constructor when initializing the Pig client. Would you like me to help you with setting up the environment variable or modifying your code to include the API key in the Client constructor? yes , I need a python script example
The remote artificial intelligence machine move the mouse and open notepad, add source code and save to my desktop.
I add my API key and I run it, see the result:
This source script is the result of artificial intelligence processing
"""
Example script showing how to properly initialize the Pig client with an API key
using both environment variable and direct constructor methods.
"""

import os
from pig import Client

# Example API key (replace with your actual API key in production)
API_KEY = "SK-..."

def initialize_with_env_variable():
    """
    Method 1: Initialize Pig client using environment variable
    This is the recommended approach for production environments
    """
    # Set the environment variable
    os.environ["PIG_SECRET_KEY"] = API_KEY
    
    # Initialize the client (it will automatically use the environment variable)
    client = Client()
    
    print("Client initialized using environment variable")
    return client

def initialize_with_direct_key():
    """
    Method 2: Initialize Pig client by passing the API key directly
    Useful for testing or when environment variables are not preferred
    """
    # Initialize the client by passing the API key directly to the constructor
    client = Client(api_key=API_KEY)
    
    print("Client initialized by passing API key directly")
    return client

if __name__ == "__main__":
    # Example 1: Using environment variable
    client1 = initialize_with_env_variable()
    
    # Example 2: Passing API key directly
    client2 = initialize_with_direct_key()
    
    # Both methods achieve the same result
    print("Both initialization methods are complete!")