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 build from the latest source on the GitHub repository:
$ git clone git://github.com/autopilot-rs/autopy-rs.git
$ cd autopy
$ make
$ make install
Note: AutoPy currently requires the 2019-10-05
Rust nightly in order to
build from source. This is to maintain compatibility with an older version of
PyO3, as the latest version has dropped Python 2 support. Python 2 support will
likely be dropped from AutoPy as well sometime later this year, depending on
how necessary it is to upgrade to a more recent version of PyO3 or Rust. In the
meantime, it may be necessary to install the required nightly via the following
when building locally:
rustup install nightly 2019-10-05 --force
This is due to rustup complaining that it doesn't include certain components
such as rustfmt
.
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.
Contributing
If you are interested in this project, please consider contributing. Here are a few ways you can help:
- Report issues.
- Fix bugs and submit pull requests.
- Write, clarify, or fix documentation.
- Suggest or add new features.
License
This project is licensed under either the Apache-2.0 or MIT license, at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
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-4.0.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a01421e7891677e3bf5a59454bf5aba76e5a2ae1435a171e64169185f1447e44 |
|
MD5 | e1df4fa20ab23855c60fc57417c436a7 |
|
BLAKE2b-256 | 079e23696c0f722162003e1f3d6450abf0fe5c4a3a9c6a26c988c59fc16cb8bc |
Hashes for autopy-4.0.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1dcf7405028ad37df0877a19fd69af9814725f919ce2af13ba1018f948cec79 |
|
MD5 | cc67b6c13ef144d327080188af7a252c |
|
BLAKE2b-256 | a188e0dad664241a060d1a3dcef0dd75d8a55819d6a8b474c39aed20c184367c |
Hashes for autopy-4.0.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5c27a6f5fc636002b4f50a6522fcfbf5f156d74e4e94907676cb55f601a2ec87 |
|
MD5 | cceb32b04017730b1472a4d7e91518ef |
|
BLAKE2b-256 | 5a2a5376a2b1cf0a6f70739cfb1ee1b875a7376538b1390088bf97cf55186ee0 |
Hashes for autopy-4.0.0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7695c933a07f60f69826053a77288a6c3a3c392e72e77d3b411cc8b430a825a |
|
MD5 | 1e4af1bef3287ba599ca1bb95adbd9a7 |
|
BLAKE2b-256 | 78629535b55b8e72b13da46deef4cef8c4b2d4a8892e7dd53504cbd734812204 |
Hashes for autopy-4.0.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6fd74465a033e7b450162a7e0e097fa8b88f1d086afe63dfd81ef6fa8e4bb9dd |
|
MD5 | d53edb183c411e72bd8c52d040a5da27 |
|
BLAKE2b-256 | 96be6c3b6f94f5c1133bf4526d177319157073764e8870c749ceb1187be99de3 |
Hashes for autopy-4.0.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5db79c63a1a913cd6026b2c093a7948f47881ad82e57befbb508b8edb566594f |
|
MD5 | 025e3d101af1fffff9e1b5b90f166731 |
|
BLAKE2b-256 | 9368de764595757ec515eff1f82b978109bd17c0a8175a69380c16bb8ef7247a |
Hashes for autopy-4.0.0-cp38-cp38-macosx_10_13_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7825aba7adb3264707499d4950d3bface9514248f4c2552abb73c7ab91f673a4 |
|
MD5 | 0c1460a5ef4d04b5f7199bcf5069ad28 |
|
BLAKE2b-256 | d821d89e99a6dd41f004a8a9c73e86b7e1bf32b3441770e74306cdb16ec7f036 |
Hashes for autopy-4.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2550e1140bef6143afe5f89004d6e3c2bb055d01178a1bd952b1c3bad20fd848 |
|
MD5 | a2b265b504d85825ba6844391cf54dca |
|
BLAKE2b-256 | 7f6b176c50e9352f2fc4b86b722d3a7252006dbf903e0c406b5fe542a299ff02 |
Hashes for autopy-4.0.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eed244e42d24ecf20f90c5672fb6d859b031de567bb178c0b3e3617acd5eed59 |
|
MD5 | 47fdc4ccd2438ca7a2bdb5854197ff24 |
|
BLAKE2b-256 | 0b5412aeff9b4b2e7d2b477d2131112dabbef522305787bbe59632fc2491fb1a |
Hashes for autopy-4.0.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 281252a0a47b691f4996ecc0f42545c1b0ec23568a8c04abba4dec6f08d29892 |
|
MD5 | a36bc02d073adcfa5c3fe6ae182d45ea |
|
BLAKE2b-256 | 09af0533dd89bf866616f8ccd6f31da708a28a73ce163a983be54ef0c1918286 |
Hashes for autopy-4.0.0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c739476056913e61415d5e2d2cff8e3e3aa9dd272bf091f7068d47cf18f3f00e |
|
MD5 | 94038d131204f571758f228341447d7a |
|
BLAKE2b-256 | 028bf9b034ecb6634dfbbd2e5bf9aa116bcb0a17b565aa43096c24ade01093aa |
Hashes for autopy-4.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4584eefd5534e84b80cdce6517d94fc93ea7c1b7fe863a3ed5a74c8fc61b8eb6 |
|
MD5 | 1b012b3c28cb3f025ba8134f06d396fa |
|
BLAKE2b-256 | 334c83538adc1b55af175053fc420853a19c6ac961003e28b2a20b8bf0ef46f8 |
Hashes for autopy-4.0.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5a5bb85f475b9d7305771dfdf6e35f2e4abb5c2198f8bef9f8b14928946caf25 |
|
MD5 | 7c65176fd84a321dec8138af1df0098c |
|
BLAKE2b-256 | b82e4df90e71bf1d1d0498f4833e6259f2e461579905abc7e5ca2d89ce73132b |
Hashes for autopy-4.0.0-cp37-cp37m-macosx_10_13_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e631d743f5e445362a8bbdbfd095230979d4da54ad1e77b275deeab602dd3e81 |
|
MD5 | 45e4f78f101647d80e7c43c427051655 |
|
BLAKE2b-256 | f32a4b161a3d812087120b6b58c5acb2cb99db25f6cd97d77c3a1ccc2946944c |
Hashes for autopy-4.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f87561f9047c70b87614370be0cc550a1c138fbaacd7d5eaf2eb092eee21018b |
|
MD5 | 15e206a9586cb152358cfe452c39699d |
|
BLAKE2b-256 | f1d1a8da38a04b05b5107df7c9447de301cc7af0a5f7ede33dd99d0c812344a4 |
Hashes for autopy-4.0.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 470cfaa6d01bd5e1ed489f199fb248dd7a2dc0c6b60dc1c6b3d07a37914678b7 |
|
MD5 | 90013ad2b273c486909b4204b36cc7b4 |
|
BLAKE2b-256 | 105efeae30e57af3eb4d7cffb3ecc61ed1c548e0e85d54ef135f2d4463dcb590 |
Hashes for autopy-4.0.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 818acf78fc715acdd8e7dbd4ba58abe00ade8bb71bbc40d413fbd650ab195d0e |
|
MD5 | 1c34b252567b3789785fe7acc8098e9f |
|
BLAKE2b-256 | f46c7baccf39d66514d2f5712858c9b736b471167e299cc5ea7f4c308d022766 |
Hashes for autopy-4.0.0-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebef27afdb81c260146e9d42aa2952cf3cbd91389b88ff967685fba1dce24a14 |
|
MD5 | 7e5bde8095b11694941e41c7fd6d1041 |
|
BLAKE2b-256 | 0177c7e6880026c2a6bdd46d0589d24c809eb9f4ad1dc75e922e62ef7cdbd86d |
Hashes for autopy-4.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69312d6912381f06b62853fdd8f659902fa52a62e18513c46f8d0eae7c3f5bb2 |
|
MD5 | 14cf1daa878b2c940e7420b91a66f811 |
|
BLAKE2b-256 | e12e6a956768cd84f8c6c5bfff9dd5a64d62722c2893b6a097ec27ce8ac96380 |
Hashes for autopy-4.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41f246640b848e6db49f9a25ea285442c4a8c1742d3518413a71ab12920f94cf |
|
MD5 | ee7016276bc915e25b75536193afd0a6 |
|
BLAKE2b-256 | bf48f967f7c7b08fe86f54b1fcc96eefd86aabde61d8228f68826d89ce7bbfa8 |
Hashes for autopy-4.0.0-cp36-cp36m-macosx_10_13_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4f39825a3a71048e3893a49c9902ba565ef76aaed8dfffc260db4e7071bdd9a |
|
MD5 | ec92c7d488106a846a044208eb8b70d5 |
|
BLAKE2b-256 | 1e8c36e1c1c5f01c16d754531a07e5f19bff3318e61d6d975089ecdc561d9acb |
Hashes for autopy-4.0.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ff259b644a8df27a2810625dfd7564eecfba8a79e0031036eac6a0491f0c014 |
|
MD5 | 10d93a65c260fe7ba93c7cd82a6dec56 |
|
BLAKE2b-256 | 5a0fa3a02c5d2a1279bc61c89743d97208ddabe7967d8dabaa4eef6373297fc4 |
Hashes for autopy-4.0.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87c99fb12a2d271f9304cffc2320de5148677b0bd1aeda5c54f7ec89f29ed0d1 |
|
MD5 | b37ad3f5dc4798d6bd830d68e630f787 |
|
BLAKE2b-256 | 1313a70f01b5a920247acf2c24bdd3a9f57c1c1dec775f5b3f036168968030e6 |
Hashes for autopy-4.0.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d0c82c68b0a89215037d43f8195d5b5ccce35bae534f637d3356f392585686a |
|
MD5 | 143d945000e980494c9c6fe17336d64a |
|
BLAKE2b-256 | 840e62ebc8fdb065e88a0b1219257adc46bac2069736e0d84242ec39d6f7364a |
Hashes for autopy-4.0.0-cp35-cp35m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6af1b26005d2761481692d6c2d39dda2af1bff850c92612e2c550297f791a163 |
|
MD5 | 98cb3a52ba3cdaea320fd6252c538d5a |
|
BLAKE2b-256 | 2d44b2ddacd370a6e56a7367526cff447b6d309145d62b9677c9b3bd98a37e0e |
Hashes for autopy-4.0.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 09b4ff0f66c6f238aa2fdb8149bc5fe92619cb29f0ef4c33886546d5ad05ee36 |
|
MD5 | 175414c389987d8fbf2668cca82e99dd |
|
BLAKE2b-256 | 8d09a51b3d22d1442320a7a0119e79e433cdd9aaf002d88846db0f83a55a9a4a |
Hashes for autopy-4.0.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3cf1ebf7fa4f7b1594f2e707dda51a20ef93e0696c59ff160e73a632aa18055 |
|
MD5 | ce0a10148633843e7c513e8cfdd14c64 |
|
BLAKE2b-256 | 075a0246f8add38975db13b11f6eeece50cc21bf0cd9dc04df9438e6eec06c5e |
Hashes for autopy-4.0.0-cp35-cp35m-macosx_10_13_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a66d3af3bd5a2869054c730b64664a2ae3d2890e8145b7b1022ebc3915b9368 |
|
MD5 | 3cc09121ed1bccd23f26bd8258623290 |
|
BLAKE2b-256 | 084f717df391145aa85749432e8724a89fe2aa9132cbeb4f76fcce2ac06c85d4 |
Hashes for autopy-4.0.0-cp27-cp27mu-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c29833f79bbcf14409c07af72a74f2dc1ea572cfcdb3545a7574c21ac922869f |
|
MD5 | 4c5f17f6a4853785021042b5c21d2582 |
|
BLAKE2b-256 | 085ee4116d9dcdc769211a3188e9ea1b5fe6a37bfc44f24ffef71ec32ba3ec83 |
Hashes for autopy-4.0.0-cp27-cp27mu-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58dcce067072dd2e9b15cb56dc15ba838c30e93f235d1ba3bf5f679e0f31cb4a |
|
MD5 | eba6d40c1374780fd1b19070cfe34808 |
|
BLAKE2b-256 | cd1b2d676b31463e758b9140217e604c24807a1fde10575e50f6ac458fe5b398 |
Hashes for autopy-4.0.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e1369b57b5dc1cc48fed3c121d14ea05a46ef14cbb7f9188e723b864acebbef |
|
MD5 | f531508c3e1c07bd639a1de465e808fd |
|
BLAKE2b-256 | 57cdc9eec69dd1e0d7c4a08ca3b7117526b29dfc09b26d29f6dc5109949d5a87 |
Hashes for autopy-4.0.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5fa07181cbafaedf330179865f54996ea35b86d6fe299d0d5ebc145a08232a5c |
|
MD5 | e20b33db8e2f2a4afebc0f48923adc48 |
|
BLAKE2b-256 | 225235d2cbde115d6dce82144fe8f35e2cfcd24bc6d415d3a6c90d049fa1c3e3 |
Hashes for autopy-4.0.0-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc8600dfe0fae831dff138ddf54c9afbc0dc482cc1f34f4278c56eb11fb5d76d |
|
MD5 | bdb03608c244939ed61b476b4459212b |
|
BLAKE2b-256 | 0bb4e9338017435cc1fccf0669ab6c2b351619922f342d10e2e3685b07fe6945 |
Hashes for autopy-4.0.0-cp27-cp27m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed3106ed017fa6800c76d30a9c0cbc527559a616a62e83aa10e9f08365cd852a |
|
MD5 | e1e9de05b5fba2d74d1f881cb9f5bb35 |
|
BLAKE2b-256 | 99806f584fb7ceefc4b7299dd558aaf01581cd9d6c85457e655def641ece87e8 |
Hashes for autopy-4.0.0-cp27-cp27m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 531477fe15779f6a46d05885f93ecdb3e21fa164c4b1eaf500b09c8c3828286e |
|
MD5 | 7ff6d9ef90ecb723681723955f35d3c9 |
|
BLAKE2b-256 | 450274cd9f2b291e6205474c8bbf0d6338fdea4b9da56c2dcb9566c94318767d |
Hashes for autopy-4.0.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 391e20225a3c46d053f03df07653a738609117ef9a0036eb62bd503074c49540 |
|
MD5 | 649cc9e9b40476d498c6e480600be2b5 |
|
BLAKE2b-256 | a596cf22197f14d5c7b9bfe41ff133c65c1aaacc079f01d6abdb13fe8fb4f479 |
Hashes for autopy-4.0.0-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2996e8c31c59994844da50fc3813098c79c1e8b426c97c9ed09f60faeb80e925 |
|
MD5 | a6e0891c5371952bd0747f6a86eba673 |
|
BLAKE2b-256 | 0c44bc68ef7b4e0a8f585c36afb2bd6a4bc6e60805a781c80646c3ea15ee674f |
Hashes for autopy-4.0.0-cp27-cp27m-macosx_10_13_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 75ad7df585c37fa11f391dcd3565086455f924881fdaf80d8edccf05b9d72fa6 |
|
MD5 | 3e9058667b8d0ce4bccf83f68727c51a |
|
BLAKE2b-256 | 04cd5a20bf0b9e2093865b64c7a66e9dfc290cf9d20d162a46f62f1b56dc8356 |