Advance GUI automation
Project description
PyAutoGuide
Advanced GUI Automation with Workflow-Based State Management
PyAutoGuide is a Python library that provides a declarative approach to GUI automation by modeling application workflows as state transitions between UI elements. It combines advanced element detection with state machine patterns to create robust, maintainable automation scripts.
🌟 Features
- Workflow-Based Architecture: Model your application as workflows with state transitions between UI elements
- Advanced Visual Element Detection: Supports both image-based and text-based element recognition with sophisticated matching
- Flexible Region Specification: Mathematical region syntax for targeting specific screen areas with precision
- Automatic Navigation: Intelligent pathfinding between UI states using graph algorithms
- Action & Navigation Decorators: Clean, declarative syntax for defining workflows and state transitions
- Reference Image Management: Directory-based image reference system for organized asset management
- Object-Oriented Element Operations: Fluent API with method chaining for complex element interactions
- Color-Based Detection: Advanced color finding capabilities with directional search
- Multiple Result Handling: Sophisticated selection strategies for multiple matching elements
- Integration Ready: Seamless integration with PyAutoGUI and other automation tools
🚀 Quick Start
Installation
pip install pyautoguide
Basic Example
Here's how to automate a simple login flow using the new workflow-based approach:
from pathlib import Path
import pyautogui as gui
from pyautoguide import ReferenceImageDir, WorkFlow, text
# Initialize reference directory for organized image management
refs = ReferenceImageDir(Path("references"))
# Create workflow
workflow = WorkFlow("LoginFlow")
# Define navigation between UI states
@workflow.navigation(
text("Username", region="x:2/3 y:(1-2)/3"), # Source state
text("Dashboard", region="x:1/3 y:1/3") # Target state
)
def perform_login(username: str, password: str):
"""Performs login and transitions to dashboard."""
refs("username_field").locate().click()
gui.write(username, interval=0.1)
gui.press("tab")
gui.write(password, interval=0.1)
gui.press("enter")
# Define an action that doesn't change state
@workflow.action()
def add_item_to_cart(item_name: str):
"""Adds an item to cart without changing UI state."""
text(item_name, case_sensitive=False).locate().click()
refs("add_to_cart_button").locate(region="x:2/3 y:(2-3)/3").click()
# Execute workflow with automatic navigation
workflow.expect(
text("Dashboard", region="x:1/3 y:1/3"),
username="user",
password="pass"
)
# Invoke actions directly
workflow.invoke("add_item_to_cart", item_name="Product Name")
📖 Core Concepts
WorkFlows
A WorkFlow represents the automation logic for your application. Unlike the deprecated Scene-based approach, workflows focus on element transitions and actions:
from pyautoguide import WorkFlow
workflow = WorkFlow("MyApp")
Reference Elements & Image Management
PyAutoGuide provides sophisticated element detection and management:
ReferenceImageDir
Organize your reference images in directories:
from pathlib import Path
from pyautoguide import ReferenceImageDir
refs = ReferenceImageDir(Path("references"))
# Use as: refs("button_name").locate().click()
Direct Element Creation
Create elements directly for text and images:
from pyautoguide import text, image
# Text elements with advanced options
text_elem = text("Expected Text", case_sensitive=False)
# Image elements
image_elem = image("path/to/image.png")
Advanced Region Specification
PyAutoGuide supports sophisticated region syntax with mathematical expressions:
# Search in top-left third
text("Login", region="x:1/3 y:1/3")
# Search in middle horizontal band
text("Welcome", region="y:2/3")
# Search spanning multiple columns/rows
text("Header", region="x:(1-2)/3 y:1/3")
# Complex mathematical expressions
text("Content", region="x:(2-4)/5 y:(1-2)/3")
Object-Oriented Element Operations
PyAutoGuide provides a fluent API for complex element interactions:
# Multiple result handling
text("Button").locate(n=2).select(i=1).click()
# Directional operations
element.locate().offset("bottom", 400).click()
# Color-based detection
element.locate().find_color(
color=(226, 35, 26),
towards="top-right",
region="x:5/5 y:1/4"
).click()
# Chained operations
text("Item").locate().first().offset("right", 50).click()
Navigation and Actions
The workflow system uses decorators to define state transitions and actions:
Navigation Decorators
Define transitions between UI states:
@workflow.navigation(source_element, target_element)
def transition_function(**params):
# Perform GUI operations that lead to state change
pass
Action Decorators
Define actions that don't change UI state:
@workflow.action()
def action_function(**params):
# Perform GUI operations without state change
pass
WorkFlow Execution
Execute workflows with intelligent navigation:
# Navigate to specific UI state (finds optimal path automatically)
workflow.expect(target_element, **action_params)
# Invoke specific actions
workflow.invoke("action_name", **action_params)
# Wait for elements to appear
workflow.wait_for(element, timeout=60, interval=1)
Element Detection
PyAutoGuide automatically detects visible elements and manages workflow state:
# Get currently visible elements
visible_elements = workflow.get_visible_elements()
# Check if element is currently visible
is_visible = element.locate(n=1, error="coerce") is not None
Advanced Path Finding
The library uses NetworkX for optimal path finding between UI states:
# Automatically navigates through intermediate states
workflow.expect(final_state, **params)
Error Handling
from pyautoguide.workflow import NavigationError
try:
workflow.expect(target_element)
except NavigationError as e:
print(f"Navigation failed: {e}")
🤝 Contributing
- Fork the repository
- Create a feature branch:
git checkout -b feature-name - Make your changes and add tests
- Run pre-commit hooks:
pre-commit run --all-files - Submit a pull request
📝 License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
🔮 Roadmap
- Spatial relationship modeling between elements
- Multiple workflow support
- Advanced debugging and visualization tools
🙏 Credits
PyAutoGuide builds on the work of several open-source projects:
- PyAutoGUI by Al Sweigart
- python-statemachine by Filipe Macedo
- RapidOCR by RapidAI contributors
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyautoguide-0.4.0.tar.gz.
File metadata
- Download URL: pyautoguide-0.4.0.tar.gz
- Upload date:
- Size: 63.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0227042a7ab7b76d5fafee7b856e6b91f673449634cb59d7775f65a372a81225
|
|
| MD5 |
c815210b4a134688694f05a15c43f6c9
|
|
| BLAKE2b-256 |
f0d2e6f1495ad9f008db944caf1bd3a03e216bac7d1515a78312b29459ebdfc1
|
File details
Details for the file pyautoguide-0.4.0-py3-none-any.whl.
File metadata
- Download URL: pyautoguide-0.4.0-py3-none-any.whl
- Upload date:
- Size: 26.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
52df8994cde26f2f805c08ee509f58e26b7a8c8cfd27c878a6cfa8255cc81e50
|
|
| MD5 |
059dfb378c393aa41ecac29be1b325f2
|
|
| BLAKE2b-256 |
ab24a05994251cd14451ad6df1f74c44f0468466c24258b2fdcfd26be078ce1a
|