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 requestsuccess
: 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.5.2.tar.gz
(54.8 kB
view details)
Built Distribution
File details
Details for the file wuying_agentbay_sdk-0.5.2.tar.gz
.
File metadata
- Download URL: wuying_agentbay_sdk-0.5.2.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
Algorithm | Hash digest | |
---|---|---|
SHA256 |
0d55d39fad95eb395666c6f576a62fcf9a8978b47f346a53a66d3c8e64a91379
|
|
MD5 |
130a5b3a7a8d2c40409ae7750cfa09c5
|
|
BLAKE2b-256 |
a54314fbdfa7a51a6cb9d76b65b14fd9157685db0459a74b88f6c6770bc1e1c8
|
File details
Details for the file wuying_agentbay_sdk-0.5.2-py3-none-any.whl
.
File metadata
- Download URL: wuying_agentbay_sdk-0.5.2-py3-none-any.whl
- Upload date:
- Size: 92.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
ce4c185f297e8a067586cc0514f53ab3d8787b29292a3009fc4f94c35259b42e
|
|
MD5 |
6b95c706a6faa11c56c262dc6c3ab101
|
|
BLAKE2b-256 |
1b37e340135253e5c076f965a7b6b39c078b28c6854f450d00b2769038546f2d
|