A simple, cross-platform GUI automation library for Python.
Project description
For more information, see the GitHub Repository.
AutoPy Introduction and Tutorial
Introduction
AutoPy is a simple, cross-platform GUI automation library for Python. It includes functions for controlling the keyboard and mouse, finding colors and bitmaps on-screen, and displaying alerts.
Currently supported on macOS, Windows, and X11 with the XTest extension.
Getting Started
Requirements
- Python 2.7, or Python 3.5 and up.
- Rust 1.23.0-nightly 2019-02-06 or later (unless using a binary wheel distribution).
- macOS 10.6 and up.
- Windows 7 and up.
- X11 with the XTest extension.
Installation
First, see if a binary wheel is available for your machine by running:
$ pip install -U autopy
If that fails, install rustup and then run:
$ rustup default nightly
$ pip install -U setuptools-rust
$ pip install -U autopy
Another option is to compile from the latest source on the GitHub repository:
$ git clone git://github.com/autopilot-rs/autopy-rs.git
$ cd autopy
$ rustup default nightly
$ pip install -r requirements.txt
$ python setup.py build
# python setup.py install
Additional instructions for installing from source on Windows are available here.
Hello World
The following is the source for a "hello world" script in autopy. Running this code will cause an alert dialog to appear on every major platform:
import autopy
def hello_world():
autopy.alert.alert("Hello, world")
hello_world()
Tutorials
Controlling the Mouse
AutoPy includes a number of functions for controlling the mouse. For a full list, consult the API Reference. E.g., to immediately "teleport" the mouse to the top left corner of the screen:
>>> import autopy
>>> autopy.mouse.move(1, 1)
To move the mouse a bit more realistically, we could use:
>>> import autopy
>>> autopy.mouse.smooth_move(1, 1)
Even better, we could write our own function to move the mouse across the screen as a sine wave:
import autopy
import math
import time
import random
import sys
TWO_PI = math.pi * 2.0
def sine_mouse_wave():
"""
Moves the mouse in a sine wave from the left edge of
the screen to the right.
"""
width, height = autopy.screen.size()
height /= 2
height -= 10 # Stay in the screen bounds.
for x in range(int(width)):
y = int(height * math.sin((TWO_PI * x) / width) + height)
autopy.mouse.move(x, y)
time.sleep(random.uniform(0.001, 0.003))
sine_mouse_wave()
Working with Bitmaps
All of autopy's bitmap routines can be found in the module autopy.bitmap
. A
useful way to explore autopy is to use Python's built-in help()
function, for
example in help(autopy.bitmap.Bitmap)
. AutoPy's functions are documented with
descriptive docstrings, so this should show a nice overview.
>>> import autopy
>>> autopy.bitmap.capture_screen()
<Bitmap object at 0x12278>
This takes a screenshot of the main screen, copies it to a bitmap, displays its memory address, and then immediately destroys it. Let's do something more useful, like look at its pixel data:
>>> import autopy
>>> autopy.bitmap.capture_screen().get_color(1, 1)
15921906
AutoPy uses a coordinate system with its origin starting at the top-left, so
this should return the color of pixel at the top-left corner of the screen. The
number shown looks a bit unrecognizable, but we can format it with Python's
built-in hex
function:
>>> import autopy
>>> hex(autopy.bitmap.capture_screen().get_color(1, 1))
'0xF2F2F2'
Alternatively, we can use:
>>> import autopy
>>> autopy.color.hex_to_rgb(autopy.screen.get_color(1, 1))
(242, 242, 242)
which converts that hex value to a tuple of (r, g, b)
values. (Note that
autopy.screen.get_color()
, used here, is merely a more convenient and
efficient version of autopy.bitmap.capture_screen().get_color()
.)
To save the screen capture to a file, we can use:
>>> import autopy
>>> autopy.bitmap.capture_screen().save('screengrab.png')
The filetype is either parsed automatically from the filename, or given as an optional parameter. Currently only jpeg and png files are supported.
>>> import autopy
>>> autopy.bitmap.Bitmap.open('needle.png')
<Bitmap object at 0x1001d5378>
Aside from analyzing a bitmap's pixel data, the main use for loading a bitmap is finding it on the screen or inside another bitmap. For example, the following prints the coordinates of the first image found in a bitmap (scanned from left to right, top to bottom):
import autopy
def find_image_example():
needle = autopy.bitmap.Bitmap.open('needle.png')
haystack = autopy.bitmap.Bitmap.open('haystack.png')
pos = haystack.find_bitmap(needle)
if pos:
print("Found needle at: %s" % str(pos))
find_image_example()
Projects using AutoPy
- AutoPyDriverServer, AutoPy through WebDriver or a webdriver-compatible server.
- guibot, A tool for GUI automation using a variety of computer vision and desktop control backends.
- spynner, Programmatic web browsing module with AJAX support for Python.
- SUMO, An open source, highly portable, microscopic and continuous road traffic simulation package designed to handle large road networks.
API Reference
Hope you enjoy using autopy! For a more in depth overview, see the API Reference.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for autopy-3.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5c3400796f52bb7c8dc3596105017bae0bad93bdacdb3d7175c6f137eba55b2 |
|
MD5 | c09ebab1bd576c147de7d1d3f0f10bde |
|
BLAKE2b-256 | cf9ebb0349d09666bf45caa5f253fd9abedfa39e8391fbcd2cddf47f76eca90b |
Hashes for autopy-3.0.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1774195987fe8ab2e22b9f4d84f99fb00bc2acf312d3ba3330c1f9cc0f603498 |
|
MD5 | c9683ee7b2891197d5f2c3130c2bc3d5 |
|
BLAKE2b-256 | c74e9b8da75ab20bc4e4295ab9ad8b8c885824ba0b0e5a415c4a0ee90ed3a5d7 |
Hashes for autopy-3.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13b9125b846b6dca343ad6b9dda579dd9f8db460b53b912f48d404782c3b7a48 |
|
MD5 | 42070957257180289ddd492bdb2e1149 |
|
BLAKE2b-256 | 49c74d46c960e9c067973733ba7148fdbb2a774260229a8f792295ecf12a445a |
Hashes for autopy-3.0.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71fdca8d0eb55481f6ed3bbbba676938111dec0e65aeeabffd254c8153e85247 |
|
MD5 | b8482c69ad6551977d6cb4b448ab44d4 |
|
BLAKE2b-256 | 9e74765923ffd09b5382d2d45456b37bd14ce1083ff2eea4fed2e741bd53c0bd |
Hashes for autopy-3.0.0-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 684a5844cda74fb23a143724cc7928c5f4c29637b94dee5172406cce171cb3dc |
|
MD5 | 1a0f42798a10cc4b9330df229bac4c97 |
|
BLAKE2b-256 | 2c81f005b2ba204245463b7790053262b9c3f8b8ac7d44d263dff674212b385c |
Hashes for autopy-3.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5730015d847f62a3865b451cdc6df4022c50973f1a04cd8c9eabb458ecb78f38 |
|
MD5 | 7de599979e9cfe0537e585154afff6b3 |
|
BLAKE2b-256 | dd450c888a47a0a4e9530d994d9d5012f6dc7da35bbd757a6366d0aa6858d2a8 |
Hashes for autopy-3.0.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9776cafa8f765506efc932418b02f85d962e02261189cc62f60adebc50bd435 |
|
MD5 | 485c5ebdba83a69d92561b65a0ac63a4 |
|
BLAKE2b-256 | 9575e8c167c63a92d476a976f780c2aed286896f8519224dc1f6998538760508 |
Hashes for autopy-3.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9608851730a64d780f15be65415974d1051c29e4ee19c08e28b45f3a4bc7390 |
|
MD5 | 0e428291a5d20bdaebb3ad5cc4bdae58 |
|
BLAKE2b-256 | c24893a08029317ac0e537a9853a83ff82dafead9065598870a87b87da69f48b |
Hashes for autopy-3.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 64e3186bb1b3f1e20cc6c4827b17fcf43fdac01c1fd09fa4e60957c9eec1552e |
|
MD5 | c5213170011a0f2f27f68ed098e98b43 |
|
BLAKE2b-256 | f40ea319b56c2c07a8d628c8812b38ab0279b5511e0412be0f5b8cd381fe3ec2 |
Hashes for autopy-3.0.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a881132fff215a76273db4cf9f39cd4e7027994f84f892937ac205c7e6bc2c26 |
|
MD5 | 12e45edd43f36cad98d852c940da5fcc |
|
BLAKE2b-256 | 99d1159f4f6f37ece713a963f3787acbe638c013485f0dd4f958b29dd44276c8 |
Hashes for autopy-3.0.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b49f3cd7922c755d6f52852e425075be1147aa0a5fa57abe17d009d599011c72 |
|
MD5 | 9dbf85a4ba4b7faad3ca7876ca8be374 |
|
BLAKE2b-256 | 1db30d265c47b7bfa9a25db31b0c9a6ab9b47052bd4ca03e63341aad1003c824 |
Hashes for autopy-3.0.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2733761900acd3ce558efec89d1da118eb0335d804a84dabe50a9cb5b465828b |
|
MD5 | ad5b891ff323d2b8ea9c35fc13142e06 |
|
BLAKE2b-256 | 63a04983118fd6e578953beb4862144e9f1f7a901a5376b2bc6e3e87407de77f |
Hashes for autopy-3.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f19cba924d9c1f17e0ecb2a2d7dc9a51effdb2c660127f8a6591801a6e2e429a |
|
MD5 | f7a3f4169c7f1abe4206506a43b9ebac |
|
BLAKE2b-256 | 7f0fe02e007d779553016c4d7db1c90453a8e3f9d4b7c10137be40bea79371c5 |
Hashes for autopy-3.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c0481e661ce33ec0c4ccbea2bdec82aeaef288b63b4fe977bf37946c208e00a |
|
MD5 | 9264858b4b9a2ef2c231eebe5a820d4a |
|
BLAKE2b-256 | 09d2c266b6a4962f05bdba312b493ae5473c0a538d17a29382123140bcb6ecbc |
Hashes for autopy-3.0.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 722d9b5e9ed9d3ec5d39144ef37165ae8d12c379719aa437c1e7a4d2acdd91f0 |
|
MD5 | 694d3ef5eac47f7795bc3c2c5e3f52ce |
|
BLAKE2b-256 | 47596bbefb96b3c184d04563c871964b3d320868fa9768579d6aba271ae22e9d |
Hashes for autopy-3.0.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a32629a77ad8d55b904aab2f583ce0741e12b6ed14ebb52d1bafb14b9bc6058 |
|
MD5 | 0e6acc4870ff3d7ed80268a3c7903b50 |
|
BLAKE2b-256 | ae284d3596a0dca632d1af172a1141060ee13b48a6cadab6071851fa7a881038 |
Hashes for autopy-3.0.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | af21c484245e2b2dc546e7efe27f1eba6cba4c9823f309a9f5189546778a244d |
|
MD5 | 9339769709ef158793d7579bdaa0cacf |
|
BLAKE2b-256 | 3651ef1967cc950f817bf9e173128cbe012dfc8d6d91d849c377e1767a08bbe2 |
Hashes for autopy-3.0.0-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 230308f7a244752fdf6f7d38b0ea8436006fa70803388df43089dafbfef69ce4 |
|
MD5 | 806c2e199b00f5dbe0cb40b6e473e3a4 |
|
BLAKE2b-256 | 2092296db319e29018cd670ce0fddfa3abfc71a49dbe570e2608012e686e2375 |
Hashes for autopy-3.0.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee727e1182d4e997780efc9ea78067f803ae7829489ec8fb24bed2c45d5de6d3 |
|
MD5 | 1918f9a7c09531438b6db7c28e1b795d |
|
BLAKE2b-256 | 39bf6d9de2660ffd572bd818095676f35315d2c1f57c454be0125e6630f05345 |
Hashes for autopy-3.0.0-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 18b530c4fead88541e7923d6b10db557518f129a82d32397db2746885cb15d72 |
|
MD5 | bdfb47417e647a480b2b6504e7a4e521 |
|
BLAKE2b-256 | 9074a0a50caf153b6b9722084fde27f9b29591ecf5f243dcfa924586019852c5 |
Hashes for autopy-3.0.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9132925e15e5c23cf4a8bdcc20a19a850a2bc1a701fb7d3610441cdd78de5c25 |
|
MD5 | 7465bd76883843e9259960f91128151a |
|
BLAKE2b-256 | 1e4de8bd75b926470f309edda0dde46670f83ed088c5d6729a61018248ab526f |