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-2019-10-05
$ 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-2019-10-05
$ 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()
Controlling the Keyboard
The following will enter the keys from the string "Hello, world!" in the currently focused input at 100 WPM:
import autopy
autopy.key.type_string("Hello, world!", wpm=100)
Alternatively, individual keys can be entered using the following:
import autopy
autopy.key.tap(autopy.key.Code.TAB, [autopy.key.Modifier.META])
autopy.key.tap("w", [autopy.key.Modifier.META])
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()
It's also possible to do a bounded search by passing a tuple ((x, y), (width, height))
:
haystack.find_bitmap(needle, rect=((10, 10), (100, 100)))
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.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b10ab2b56bf879681c899f845ef91c280e6e3a4c604da22d1aad619f67066d76 |
|
MD5 | acb7839d36c21935fa63ea95b9ae4e20 |
|
BLAKE2b-256 | fe2c33704f4e63397b7e63b9be9c431c02fe71f6fda9a4680b90ac4bd328ac08 |
Hashes for autopy-3.0.1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d9bc8a9e5008afb70c11e8421410c76a22a0f571ee4a96d9b61b56413119f06 |
|
MD5 | 3128695a33e36eaef2e60f63e6e16851 |
|
BLAKE2b-256 | cc4cad605478440873668b4b439a6111e70c1ae40a9be468f91005302602a791 |
Hashes for autopy-3.0.1-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7f246cc2e10393682092e5807d923f64e0d56fc0b40db7f25b0a627211f85ace |
|
MD5 | 9b00aa67774440b4d60239f27142a75c |
|
BLAKE2b-256 | b70de3b8d55f4c6552d9624380259d166caea9d001c6250f443e5f3d2185067f |
Hashes for autopy-3.0.1-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0916d655bf5d7c90148faf1e7d6c7f0a2e3a9bf7a5ebdfeb86f87a6cdab86e8 |
|
MD5 | 74de2bce6c4d2fedafe69ff06f542b0f |
|
BLAKE2b-256 | 0d2f6bbfb53051ed5700847cf6fc4fd1bfb38fae0e1f30165f3d4a5a50689b7c |
Hashes for autopy-3.0.1-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b01b3cf5c7db90b320e86395649c0e2ad1a6fdc0e6c3ba689c2d7acf8a9da5a6 |
|
MD5 | 5d00183836a9879b72141be05ca67ea5 |
|
BLAKE2b-256 | cb8c45c0cc6d5fc5672d06877b557b6ded68f5102bd0e8fdcac864f95a8865de |
Hashes for autopy-3.0.1-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1fcef0774285a1e1caea9df0fe1c7fb4a103ea0bfd81d83f4825c398f9886461 |
|
MD5 | 5a942665356f1702e29540e63656db5d |
|
BLAKE2b-256 | ed6114ac4e5312d74252f1f6dc1bf6d6ecc1bf9772be59f12b7d88b5d577b98c |
Hashes for autopy-3.0.1-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c156799dcb7c16d456a9909199667554c8ec3b907d2545e75fad1823a5506ba5 |
|
MD5 | b5b8922877948092f9558011abe56c33 |
|
BLAKE2b-256 | c55371d6534cd5b5ed8f9548ea396c64ee66fee715d93f36bd5762a9a69a1201 |
Hashes for autopy-3.0.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97d4998b307b3b3ad6a8625bfcc0bb2ed187da64f11681fcc3885e0118c0d4af |
|
MD5 | d45c5786309bec9351fcaa0e02a6c80e |
|
BLAKE2b-256 | f901606a3a2459081b4c85bd8f8bd9e6e31fd804629dcf2a5c358bd6c73f97da |
Hashes for autopy-3.0.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 047a3f18f004cc84b6f5131878c98710d3879f6ba3371c6a07d946c49b1b71af |
|
MD5 | 356090f7a8f97a7fbce98c20686af1f9 |
|
BLAKE2b-256 | 78ce2f9fc22d570f4a32038a04c5b872f029f6db21b3719fe4393eba4f4ba3e4 |
Hashes for autopy-3.0.1-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3ea0436bacaf957fe98165ff0748709c2b301e87f45fc083173d011289e28b0 |
|
MD5 | 87e5355108fa382b3818670832cf1c63 |
|
BLAKE2b-256 | a7cafb229e65f26f2dfbb665b913e373defb403dfbd9cbdbccf606b9f0bb664d |
Hashes for autopy-3.0.1-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53e123e02129bf2f46cb49135f2330ab39052db14dccf493606bfa1d8bd8aef2 |
|
MD5 | 18958807964fcfcaecd20100d1edd0c1 |
|
BLAKE2b-256 | 0e893789263ec10b177d69471fd77e43cbf8cc14a46f899c33a5f04c3e60fe10 |
Hashes for autopy-3.0.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70207e4c760257946f61991744a6b7a0806d504db2a66b68a4d00fd184a2add0 |
|
MD5 | dc82c6c52f0d69cb1d7c4cd10d0043af |
|
BLAKE2b-256 | 80d53cc12996909c9c7537e3c5fceae960173b0615786f3fee619fd767d6d312 |
Hashes for autopy-3.0.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b76933199d1325c9f1877eb41b507742bca3c8bfb209d11aa46f16ebd2df8fc7 |
|
MD5 | 80469982d7df97d8785f275b9153d913 |
|
BLAKE2b-256 | 2e4dee88d817c36f4ae5ba6c518a4989f88a4f7fa158c4cc7f46568b9a3a32bf |
Hashes for autopy-3.0.1-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f09d8e1e2f8c3634027d91a99b61c6a2bef14153c37734e16c195487f8c2c883 |
|
MD5 | cde54845ddeaa455496ef62d7f4528ce |
|
BLAKE2b-256 | 23d336ed931e594cb3b7dfed01822624698db65b7935ff6b5902c6da499570db |
Hashes for autopy-3.0.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbbfa1a64403ffe16bb70282bec808d41021f6d8d1c647802e917f0acee4b94d |
|
MD5 | 4ceea98cc83ef6d490ab221d42956d3d |
|
BLAKE2b-256 | 768dc32e1159eaa43c57bcec53a7d3bf705ff98eb4599bb864cb1662ea235dc8 |
Hashes for autopy-3.0.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd8d02dd26c0506383506c489cb6ac9283a019eb11bddeb19f966703b1a1caf9 |
|
MD5 | 80f3c53076142715900864f7437fcc8d |
|
BLAKE2b-256 | da8b75387fe40e3123ebfb12b27db8dae80e5f6aad9048e8e8ae7f30652d96d0 |
Hashes for autopy-3.0.1-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 704bc119fbdc4b91fd9c62a65669ead649f3f5fef89d5ae80101e8259f81104f |
|
MD5 | e99106cc8f0cee740b8cd07970d3a49c |
|
BLAKE2b-256 | 6d639c66396d31d87666fe8a114c67004a16f5124b32f587613021af70dfbfab |
Hashes for autopy-3.0.1-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0a4d0783bf77a1e1552bc7ef0caddddd7ec5371197047891983efe8a8b0edc4 |
|
MD5 | 9d78b054670f5051bb010400b02f662c |
|
BLAKE2b-256 | 24844a75c40a71a66ac09169c90431f3f5081440e0cd738f3efde028fcfa4c46 |
Hashes for autopy-3.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8396be04bf02e96229aec0422052319f541863d3a73dd4a554e5d0bf1c16c46b |
|
MD5 | dbfafa1cad9da1fc8c6b59a33764f0e1 |
|
BLAKE2b-256 | 16acdb045b6856289edbd5e1827e9149b0515ea6fdf0ce3c455db06192457a3c |
Hashes for autopy-3.0.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e816b19aa8efa4fe2f10ba0046fa6a52d31f0c0833ba76f32cc3780c355ce72a |
|
MD5 | fffa01f22d940b653c3bb08c8b73d10d |
|
BLAKE2b-256 | f41ddfba040b996c5d44db1899132a6449c7cd95ced0374a2aa108ed395228b2 |
Hashes for autopy-3.0.1-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8225497baad130eefca91320e9954446eb16ebcbab5d216853f5f24f89209be9 |
|
MD5 | 7a261dc860106535c31884075127f802 |
|
BLAKE2b-256 | b1c26aa0790c165facaf867c0718aa53f461828523e4ec72309d02ef756070f8 |
Hashes for autopy-3.0.1-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 096522dcfab15a80eb2c51b9b91165a4da295a00cfcf32d5733385171cd8b288 |
|
MD5 | 70c447da15ad3aa193a666d283dacb3b |
|
BLAKE2b-256 | a23c96b4c73250d6112280399c4a6037c1b879573088f8239f92f92cfced8edb |
Hashes for autopy-3.0.1-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c720410618e457fdb8dd31276692a5b4eab1d4fb5ff7387e9d6fcb91485864b |
|
MD5 | 50528b99fdbb01d8accc2e2f1a1aa7d7 |
|
BLAKE2b-256 | 521b01b97fa879613d06022ae13b2fca0f65de585e4256653cf7310397b3eff2 |
Hashes for autopy-3.0.1-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db7f642374754c203f7ab1515585783e53cba9483fca946b7a6cdd926deefdfc |
|
MD5 | a91cb9e604c98a165f3d47ca84e7c239 |
|
BLAKE2b-256 | 2d5ebd140b6dbd7d45e6672a373a6a9dd2f8e38f28dbe0173b5ce54442c6cdf3 |
Hashes for autopy-3.0.1-cp35-cp35m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e85bab79357973bab4d8a170abe76d287d4f889bd6c63b4c8c716803369a708 |
|
MD5 | 6fdfff97d7a6e7dc45ddfa3bce8e2f56 |
|
BLAKE2b-256 | 31e8bbde1cd8cc58b74592722e17f94dafb5a5042e5180ece8d1cb6bcb0935f3 |
Hashes for autopy-3.0.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c03e2404486a82dd0f467c3ee2d418bd380622731a0a4221598aa6bd6f2067dc |
|
MD5 | 80eb5a8e179eb15093649e73d8935be6 |
|
BLAKE2b-256 | 3fe410dc4892adf4f2a61491822b80c562b3ad96e1714f1441b7723f568273a4 |
Hashes for autopy-3.0.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 470ed38c9e200eff759387123bc5cd32e5b1e5f1f0df46c5ae8b642542e7ef1a |
|
MD5 | 4a4d1726e838feee1e9d1f9aa46297cf |
|
BLAKE2b-256 | 5aa05ed8f3afc94802b355a0f7ae9ac4b704b3f7ea9c75c2c1e944f12be18849 |
Hashes for autopy-3.0.1-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7f1a99fc0872ede4aaa07e8e7fb1c74969880a98e5a150aebb97480daa3fa5b |
|
MD5 | ef408fb57c4062eacde1e6cdc68d50f4 |
|
BLAKE2b-256 | c967374ca3b2e35fffa9c2b3ca2a692dfe1656f46df064994e5dafcc65f67019 |
Hashes for autopy-3.0.1-cp27-cp27mu-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6220ebcfe4c70faab45a8c20480b3e6a3ce12646a5fddfba52fcc90787fb7b03 |
|
MD5 | db96194a4d3ca7a142e95a9469ba6a3b |
|
BLAKE2b-256 | 4748bcb5643230baa4666d6638f9fad2b727cfb36c1d09b1b2e14ad56f031e4e |
Hashes for autopy-3.0.1-cp27-cp27mu-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1e71249dfc49b3f6a590bbdeabf50fc10a8da336f8dddf518ea6c724d79f92e |
|
MD5 | a3ae8db7c4c9719a052b944a129ca71e |
|
BLAKE2b-256 | 6126d70595864f17b7dda83e5cfa3b2434ddae2dc5f0aac514fdc86d071ab01d |
Hashes for autopy-3.0.1-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53ec26182ad29428e1651f4f601c9a8a5fd2b13dc3a2d4678a84cda2a3ceea83 |
|
MD5 | 41592d90ab1beb61052e38806fde834c |
|
BLAKE2b-256 | 09a5c335be88f8524b1cb9900ddfa0eed5142330be0ca6ee27d0329aa5989028 |
Hashes for autopy-3.0.1-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d63c2da30d93ee948721be5d3caaa4aff518da8d523dba208c94298bede9ba6 |
|
MD5 | c4533913bce61737f471b65633da7e52 |
|
BLAKE2b-256 | b45185e7e374d49c76994f34daf42d371e0be7989cbba6eb791902b9706d6230 |
Hashes for autopy-3.0.1-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 50effd981b23f09a51224b043842c5d8384caf45ddab83ed51f7a61abeb314aa |
|
MD5 | 4b171055de61d6821eb21bd8d7a481c9 |
|
BLAKE2b-256 | c443615e7b4c0e41b197b90b8b8bc52502e4eda75da695866cd288aaa95e88d2 |
Hashes for autopy-3.0.1-cp27-cp27m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6d969d0bcc579395c7745b608c5d30cb60f72a17ee2a19ca2f9a28d04104f61 |
|
MD5 | 6c27a08ed06ec14483efacd48ad7272a |
|
BLAKE2b-256 | df08b166753182f65be753e83a0f6f43e89122e456c7222ccf16938366e275a5 |
Hashes for autopy-3.0.1-cp27-cp27m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05bc47b261a3781ca87f6c90c157351c4755ac6e949e5196066ba29a30a0f47d |
|
MD5 | bc45cb7062ccf4d3c400a355a4c7d099 |
|
BLAKE2b-256 | 581201aaae12d4a99ddcf958a03d71599fa60e5c02cd1a81b483049df59a0dad |
Hashes for autopy-3.0.1-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0e55557f96e2781cd591a55f541928b6824d08a217327e20bde22f2dfbe69489 |
|
MD5 | f42e8efe13a208e25c93d7aa2f870936 |
|
BLAKE2b-256 | e11b3cdba3ed92192c39257cb6a84b0c0a55314e5d6324496187b13548f4c468 |
Hashes for autopy-3.0.1-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89e493389a1c16bf30290aee0ac9a29834be8381119185698042b956cf80e3df |
|
MD5 | 6a2f82c43e9a23d7984d029f98fbf96a |
|
BLAKE2b-256 | 88053c09019b51fd2cff420475ff6f8ed362c2bf712604d06608234bc260d3cf |
Hashes for autopy-3.0.1-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72b4135d04daa9654447421cd62aea45d7dc5895b02fe1af7549df90e25eec92 |
|
MD5 | 60097e02d20a719a79a4fb0de96a6280 |
|
BLAKE2b-256 | e03e906b38eb729c22a5ef7b9b7b33fe7cbf73fb16501acb4f3e896bbe40551f |