Skip to main content

Python SDK for interacting with the Wuying AgentBay cloud runtime environment

Project description

Python SDK for Wuying AgentBay

This directory contains the Python implementation of the Wuying AgentBay SDK.

Prerequisites

  • Python 3.12 or later
  • Poetry (for development)

Installation

For Development

Clone the repository and install dependencies using Poetry:

git clone https://github.com/aliyun/wuying-agentbay-sdk.git
cd wuying-agentbay-sdk/python
poetry install

For Usage in Your Project

pip install wuying-agentbay-sdk

Running Examples

You can run the example file:

# Using Poetry
poetry run python examples/basic_usage.py

# Or directly with Python if installed in your environment
python examples/basic_usage.py

Python-Specific Usage

from wuying_agentbay import AgentBay
from wuying_agentbay.exceptions import AgentBayError
from wuying_agentbay.session_params import CreateSessionParams

def main():
    # Initialize with API key
    api_key = "your_api_key"  # Or use os.environ.get("AGENTBAY_API_KEY")

    try:
        agent_bay = AgentBay(api_key=api_key)

        # Create a session with labels
        params = CreateSessionParams()
        params.labels = {
            "purpose": "demo",
            "environment": "development"
        }
        session = agent_bay.create(params)
        print(f"Session created with ID: {session.session_id}")

        # Execute a command
        result = session.command.execute_command("ls -la")
        print(f"Command result: {result}")

        # Read a file
        content = session.filesystem.read_file("/path/to/file.txt")
        print(f"File content: {content}")

        # Run code
        python_code = """
import os
import platform

print(f"Current working directory: {os.getcwd()}")
print(f"Python version: {platform.python_version()}")
"""
        code_result = session.command.run_code(python_code, "python")
        print(f"Code execution result: {code_result}")

        # Get installed applications
        apps = session.application.get_installed_apps(include_system_apps=True,
                                                     include_store_apps=False,
                                                     include_desktop_apps=True)
        print(f"Found {len(apps)} installed applications")

        # List visible applications
        processes = session.application.list_visible_apps()
        print(f"Found {len(processes)} visible applications")

        # List root windows
        windows = session.window.list_root_windows()
        print(f"Found {len(windows)} root windows")

        # Get active window
        active_window = session.window.get_active_window()
        print(f"Active window: {active_window.title}")

        # Get session labels
        labels = session.get_labels()
        print(f"Session labels: {labels}")

        # List sessions by labels
        filtered_sessions = agent_bay.list_by_labels({
            "purpose": "demo"
        })
        print(f"Found {len(filtered_sessions)} matching sessions")

        # Clean up
        agent_bay.delete(session)
        print("Session deleted successfully")

    except AgentBayError as e:
        print(f"Error: {e}")

if __name__ == "__main__":
    main()

Development

Building the SDK

poetry build

Running Tests

poetry run pytest

For more detailed documentation, please refer to the main README and SDK Documentation in the project root.

Changelog

[0.3.0] - 2024-06-16

Added

  • Port Forwarding Interface: Added support for port forwarding between local and remote environments
  • Enhanced Image ID Support: Added support for specifying custom image IDs when creating sessions
  • CodeSpace SDK Integration: Added compatibility with CodeSpace environments
  • FileSystem Enhancements:
    • Added large file operations with automatic chunking
    • Improved file read/write performance
    • Added support for reading multiple files in a single operation
  • Mobile Tools API Support: Added support for mobile-specific tool APIs
  • Process Management: Added APIs for process management and monitoring
  • Window Task Management: Added support for window task management
  • OSS Integration: Added Object Storage Service (OSS) functionality for cloud storage operations
  • Command Execution Improvements: Migrated to new MCP tool interface for command execution

Changed

  • Updated API client to support the latest AgentBay backend features
  • Improved error handling and reporting across all SDK components
  • Enhanced documentation with examples for new features

Fixed

  • Various bug fixes and performance improvements
  • Type compatibility issues in filesystem operations
  • Session management edge cases

[0.1.0] - 2024-05-15

Initial public release of the Wuying AgentBay SDK with support for:

  • Session management
  • Basic file operations
  • Command execution
  • Application management
  • Window operations
  • Label management
  • Context persistence

Project details


Download files

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

Source Distribution

wuying_agentbay_sdk-0.3.2.tar.gz (27.5 kB view details)

Uploaded Source

Built Distribution

wuying_agentbay_sdk-0.3.2-py3-none-any.whl (62.0 kB view details)

Uploaded Python 3

File details

Details for the file wuying_agentbay_sdk-0.3.2.tar.gz.

File metadata

  • Download URL: wuying_agentbay_sdk-0.3.2.tar.gz
  • Upload date:
  • Size: 27.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.3 Darwin/24.5.0

File hashes

Hashes for wuying_agentbay_sdk-0.3.2.tar.gz
Algorithm Hash digest
SHA256 d9d5268f7fe650ab3c90ea0789b7f515ba799cc067f3e9c2d5ca3cb6434b32d3
MD5 563e9b4ab7799811fdc6b18af8289fc5
BLAKE2b-256 21788ba798fd61be15de13eafb65b404fcaf70e77c2da89abb6a57f7c198bec2

See more details on using hashes here.

File details

Details for the file wuying_agentbay_sdk-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for wuying_agentbay_sdk-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 98cbcf6dbcb419d39999c97d788e961e968dd2225c30b09481f26daa3e5c1d34
MD5 b459e5945c54c7efe068f1aea174b3b4
BLAKE2b-256 59ee6130057ea5c955e9cd39aff21ecdf601334628fcbe84947b86c6e4d21e02

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page