Skip to main content

Python SDK for AgentBay service

Project description

Python SDK for Wuying AgentBay

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

Prerequisites

  • Python 3.10 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 find examples in the docs/examples/python directory, including:

  • Basic SDK usage
  • Context management
  • Label management
  • Mobile system integration
  • OSS management
  • File system operations
  • Session creation

To run the examples:

# Using Poetry
poetry run python docs/examples/python/basic_usage.py

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

Python-Specific Usage

from agentbay import AgentBay
from agentbay.exceptions import AgentBayError
from 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_result = agent_bay.create(params)
        session = session_result.session
        
        # Execute a command
        cmd_result = session.command.execute_command("ls -la")
        
        # Read a file
        file_result = session.file_system.read_file("/path/to/file.txt")
        
        # Run code
        code_result = session.code.run_code("print('Hello, World!')", "python")
        
        # Application management
        apps_result = session.application.get_installed_apps(
            include_system_apps=True,
            include_store_apps=False,
            include_desktop_apps=True
        )
        
        # Window management
        windows_result = session.window.list_root_windows()
        window_result = session.window.get_active_window()
        
        # UI interactions
        screenshot_result = session.ui.screenshot()
        session.ui.send_key(3)  # Send HOME key
        
        # OSS operations
        upload_result = session.oss.upload_file("/local/path/file.txt", "remote/path/")
        
        # Context management
        contexts_result = agent_bay.context.list()
        
        # Session labels
        labels_result = session.get_labels()
        
        # Clean up
        delete_result = agent_bay.delete(session)

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

Key Features

Session Management

  • Create sessions with optional parameters (image_id, context_id, labels)
  • List sessions with pagination and filtering by labels
  • Delete sessions and clean up resources
  • Manage session labels
  • Get session information and links

Command Execution

  • Execute shell commands
  • Run code in various languages
  • Get command output and execution status

File System Operations

  • Read and write files
  • List directory contents
  • Create and delete files and directories
  • Get file information

UI Interaction

  • Take screenshots
  • Find UI elements by criteria
  • Click on UI elements
  • Send text input
  • Perform swipe gestures
  • Send key events (HOME, BACK, MENU, etc.)

Application Management

  • Get installed applications
  • List running applications
  • Start and stop applications
  • Get application information

Window Management

  • List windows
  • Get active window
  • Focus, resize, and move windows
  • Get window properties

Context Management

  • Create, list, and delete contexts
  • Bind sessions to contexts
  • Synchronize context data using policies
  • Get context information

OSS Integration

  • Upload files to OSS
  • Download files from OSS
  • Initialize OSS environment

Mobile System Support

  • Special UI interactions for mobile environments
  • Support for mobile application management
  • Touch and gesture simulation

Response Format

All API methods return responses that include:

  • request_id: A unique identifier for the request
  • success: A boolean indicating whether the operation was successful
  • Operation-specific data (varies by method)
  • error_message: Error details if the operation failed

Development

Building the SDK

poetry build

Running Tests

poetry run pytest

For more detailed documentation, refer to the SDK Documentation.

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.3.tar.gz (54.8 kB view details)

Uploaded Source

Built Distribution

wuying_agentbay_sdk-0.3.3-py3-none-any.whl (92.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: wuying_agentbay_sdk-0.3.3.tar.gz
  • Upload date:
  • Size: 54.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for wuying_agentbay_sdk-0.3.3.tar.gz
Algorithm Hash digest
SHA256 90fffa58c4fe4051e57c64ffe8ca64e81a4009b4d00b8e955055e9ba4f8fc225
MD5 37b1914741552ad6ca8ebcb6b6ab5009
BLAKE2b-256 db7bf23bbed6117047d276b8a2b3fa94ca84a57d363eede3ed2ce4a953e114dd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for wuying_agentbay_sdk-0.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 c35278c53729f18ea31bdcd6a05a077f15a5074ae8f74c5bb68b4daf38912ddc
MD5 0a816afbbb7c07824a5fa83094d57233
BLAKE2b-256 3e05d91074c520cc99ffeb79a72088d2fbbd91287312b577411ae5b47e0e6565

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