Advance GUI automation
Project description
PyAutoScene
Advanced GUI Automation with Scene-Based State Management
PyAutoScene is a Python library that provides a declarative approach to GUI automation by modeling application interfaces as scenes and transitions. It combines element detection with state machine patterns to create robust, maintainable automation scripts.
🌟 Features
- Scene-Based Architecture: Model your application as a collection of scenes with defined elements and transitions
- Visual Element Detection: Supports both image-based element recognition. (Text recognition support coming soon!)
- Automatic Navigation: Intelligent pathfinding between scenes using graph algorithms
- Action Decorators: Clean, declarative syntax for defining scene actions and transitions
🚀 Quick Start
Installation
pip install pyautoscene
Basic Example
Here's how to automate a simple login flow:
import pyautogui as gui
from pyautoscene import ReferenceImage, ReferenceText, Scene, Session
from pyautoscene.utils import locate_and_click
# Define scenes
login = Scene(
"Login",
elements=[
ReferenceText("Welcome to Login"),
ReferenceImage("references/login_button.png"),
],
initial=True,
)
dashboard = Scene(
"Dashboard",
elements=[
ReferenceText("Dashboard"),
ReferenceImage("references/user_menu.png"),
],
)
# Define actions with transitions
@login.action(transitions_to=dashboard)
def perform_login(username: str, password: str):
"""Performs login and transitions to dashboard."""
locate_and_click("references/username_field.png")
gui.write(username, interval=0.1)
gui.press("tab")
gui.write(password, interval=0.1)
gui.press("enter")
# Create session and navigate
session = Session(scenes=[login, dashboard])
session.expect(dashboard, username="user", password="pass")
📖 Core Concepts
Scenes
A Scene represents a distinct state in your application's UI. Each scene contains:
- Elements: Visual markers that identify when the scene is active
- Actions: Functions that can be performed in this scene
- Transitions: Connections to other scenes
scene = Scene(
"SceneName",
elements=[
ReferenceImage("path/to/image.png"),
ReferenceText("Expected Text"),
],
initial=False # Set to True for starting scene
)
Reference Elements
PyAutoScene supports two types of reference elements:
ReferenceImage
Detects scenes using image matching:
ReferenceImage("path/to/reference/image.png")
ReferenceText
(Coming soon) Detects scenes using text recognition:
ReferenceText("Expected text on screen")
Actions and Transitions
Actions are decorated functions that define what can be done in a scene:
@scene.action(transitions_to=target_scene) # Action that changes scenes
def action_with_transition():
# Perform GUI operations
pass
@scene.action() # Action that stays in current scene
def action_without_transition():
# Perform GUI operations
pass
Session Management
The Session class manages the state machine and provides navigation:
session = Session(scenes=[scene1, scene2, scene3])
# Navigate to a specific scene (finds optimal path)
session.expect(target_scene, **action_params)
# Invoke an action in the current scene
session.invoke("action_name", **action_params)
# Get current scene
current = session.current_scene
Automatic Scene Detection
PyAutoScene automatically detects which scene is currently active:
from pyautoscene.session import get_current_scene
current_scene = get_current_scene(scenes)
print(f"Currently on: {current_scene.name}")
Path Finding
The library uses NetworkX to find optimal paths between scenes:
# This will automatically navigate: Login → Dashboard → Cart
session.expect(cart_scene, username="user", password="pass")
Error Handling
from pyautoscene.session import SceneRecognitionError
try:
session.expect(target_scene)
except SceneRecognitionError 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
- Text recognition implementation
- Enhanced image matching algorithms
- Multiple session support
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 pyautoscene-0.1.0.tar.gz.
File metadata
- Download URL: pyautoscene-0.1.0.tar.gz
- Upload date:
- Size: 46.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d8bbd370096cd2bcae06c9757de40a7d5ad07366e90a65db39b2701132c4dbb
|
|
| MD5 |
4b60d19fe7587761e41aa34875ef60f2
|
|
| BLAKE2b-256 |
d408c0a78703c1b4efa3e8a78fa50861ab7d8a91cf31a3855048757f087721ff
|
File details
Details for the file pyautoscene-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyautoscene-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9caaa3ddb5014a76f4f64985a9cb429e6ef084474fcf607e77a83c3c0f3a6b2a
|
|
| MD5 |
2682ee7a5abafb6922ec5dd30ee9bc45
|
|
| BLAKE2b-256 |
09ebc58354b3c9032e967dc07c145ab2f673b10515a63eaff247503b2f86e5e4
|