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.
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-3.1.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a81c154dad1facb745750ea63970859610f62c76cc006a7be0f960aacfafee5 |
|
MD5 | 274279e38abbe74e5b2727ad4fa7cb5b |
|
BLAKE2b-256 | db5a7adbb404e4d3654e98fd73cab843f365b501bdec0f583d4c56ba0c7efacc |
Hashes for autopy-3.1.0-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 027ca8f0acf5f282feb4ff5e7f5dee6763f23ca25aa32b9fb3f17fd74b192cca |
|
MD5 | 3dd07faee79f9047281d3f18f7e5a2c5 |
|
BLAKE2b-256 | 6eb70ee288d053ea916014da68ba034f5a6cb3ea83524695111a2a98d7d0d8de |
Hashes for autopy-3.1.0-cp38-cp38-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9908d23497cdf61552df49f89fa454d192251e1a82b62308d42d8e77b8bbcfa2 |
|
MD5 | 72b776e224a6fdda9edf415acf2bd7c7 |
|
BLAKE2b-256 | 06fb37fd77ec206e74d9e4c4ed333fbce06d7a9a4eddde90d32670eabe7e8b02 |
Hashes for autopy-3.1.0-cp38-cp38-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05577f6150a833d5574d2eb51e22b9fdf0aea0c6cd2c40d443c5d45266a237bb |
|
MD5 | 175a14b61e91640f360934d526d87ccb |
|
BLAKE2b-256 | da0f2db4817c8a36caf27cff3afdf98c5924263fa147cce4f52a00ed22bd468f |
Hashes for autopy-3.1.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39d53d32a23fe3f6066a65b626e0dd67daa41fed42ba9c15f8abe784b9de565e |
|
MD5 | 3e2574c2a2f91955da754080b43bafef |
|
BLAKE2b-256 | d7c0efa40f398f70130b4d0f0f40431570b28b6991ce5222a281382eda06ee5b |
Hashes for autopy-3.1.0-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 427f52d99f59f5f17c91182c97ed5132f7320ebe0f27f6a7b903e67a0a806c44 |
|
MD5 | 2d1ff58e6b82bcedc8c1903929741f13 |
|
BLAKE2b-256 | dbfd1717df195a30cd173f0dc2d14266db5bc41991970d36ac643bb8d64c6124 |
Hashes for autopy-3.1.0-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a49333edec6cbb0dfb64acabce2fd889f30a7610e1d4405bc69925c36320ba61 |
|
MD5 | 996c189145b80c62ca382fb449b07d89 |
|
BLAKE2b-256 | ad24a38a3f180b9d2a27b8f4f7f7306913bc5ad5e40ec09536307112ffabea5f |
Hashes for autopy-3.1.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bc023b286d78064953e3aadf3389b04da0f67ac4e84eb1125cf82a4011af656c |
|
MD5 | aac5735afec59177c956293faeaaee37 |
|
BLAKE2b-256 | 8e74dd9950903cdd3af289b1a2b3a7aad47d087e8f933477adcfcf1548166da5 |
Hashes for autopy-3.1.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 002b9ad6fd34edd228e8b8dce194f77452f813fffe57151348ea7ce5c21400d8 |
|
MD5 | e7f5836a0baf051e91a78fa58e39a03d |
|
BLAKE2b-256 | 00537e0f93289a98057c578c2126fe7e86a4edb4ca88147d54709130363caafc |
Hashes for autopy-3.1.0-cp37-cp37m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c927275383c350fe4b12c60e41a2b40c6e67d5fef4559ee1cb2c9654a0fdb19 |
|
MD5 | 0b6a96837a0451421d7e6dd04e58cd7e |
|
BLAKE2b-256 | 6e73493773074a3619ece447d6f40138176f168775e2286977e7231fd6922df4 |
Hashes for autopy-3.1.0-cp37-cp37m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa661994ae43716cf83a53ecc29999fdb091b7fef4b381c30a595363cc96ee22 |
|
MD5 | 3f5bbdd7f029e3f8fdddb80246c06213 |
|
BLAKE2b-256 | 0b1900b36d3ebbcddda5b6e64cd970253c8ecb2c298a86a157851c215534d89b |
Hashes for autopy-3.1.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71a80228285933a73ae480fbaf23548f92c4d664e26e5ac1311fba2b49453dd2 |
|
MD5 | 105d276423280f79c4837de53326e404 |
|
BLAKE2b-256 | 627a53541af38104d32fadc080be75ad144ab2f1d3c783d976150e489aefadb6 |
Hashes for autopy-3.1.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | caacc398d735ebfbffdc542e7023ea8d0837d4732ae6fa71760679405a5326fd |
|
MD5 | 39faa0be00ebaf703d97f1e5ced90682 |
|
BLAKE2b-256 | 0fa8d493c6db84657e45408fc444660d5f15c236de561ad6650c82bbad427c1b |
Hashes for autopy-3.1.0-cp37-cp37m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88bd4657d06f8391a02aad326789a9605a31523849ceeb921a0e72b790986278 |
|
MD5 | f6805ce96e46d529478d9179862a9e96 |
|
BLAKE2b-256 | 66251e5c3567e81e8ecc60f550e476f05b1cffa443cfddb809465f3711795666 |
Hashes for autopy-3.1.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a7d8e86131ed84592c629326bf85d18864e35307542f71ae221b0e8bcac3d099 |
|
MD5 | 7557a80b89fcedf26e4c6cb0a1683ad0 |
|
BLAKE2b-256 | 19dc0977cd820accc8e18debef0f3b5712896a9cab6d5071a9db38862206adaf |
Hashes for autopy-3.1.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d16b9c8605a8a42765db8752682332a2261cb08d86b2f03d1d5f6082b04bdf3a |
|
MD5 | a28735223216833ab9010842c0764a81 |
|
BLAKE2b-256 | 59bd3c1ca0cb795b116b75af033f7dac909e689290349c0d62cebdea6dd4d940 |
Hashes for autopy-3.1.0-cp36-cp36m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1a63e88d77692291ac78b3647e5e854c4a10bc4a7d804bb6ac1255fc03b9e476 |
|
MD5 | b170b6a95c77431a83e0406437a03ea3 |
|
BLAKE2b-256 | c959d4314090bf881f4c74eea6ee4ed143e683bb9da1e41d956423220317fb8f |
Hashes for autopy-3.1.0-cp36-cp36m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6038309a27ae2041e11f99d6b025a064ea14818cf126e75073bf034ddc9f51c |
|
MD5 | 63aea75651a9193112cd48ed0a95e70d |
|
BLAKE2b-256 | 132f8013b7550f2b98a4be021f5146df56c8c031f814188cce7184d615730550 |
Hashes for autopy-3.1.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a455957cc4d16415a4ad17505deb2f50ac7e02363bd84aa022f126110d7db0a |
|
MD5 | b9ccd570006c10402cf0cd1f9e8ae300 |
|
BLAKE2b-256 | e8daa4201c281935fac5a868061a4b0bcdc0cd6a02fe6c5292245a192c1db734 |
Hashes for autopy-3.1.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | db3b95b99acb1083669fdeb2925ad0460d5826939bf2d6db3915762e1b1b6983 |
|
MD5 | bdf31025f5b8ff42589444e400553b51 |
|
BLAKE2b-256 | 5c181cd107eca62ea1319b2f2ca4a5bda77769f2448522b3d9abe6f6c8750ca5 |
Hashes for autopy-3.1.0-cp36-cp36m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96eb4a731091b8e2737297f50adef16e60411a030dda71b1cfd9425d28b30be1 |
|
MD5 | 14cdd22e1580b58e4f6613ee3b4ed8f3 |
|
BLAKE2b-256 | 2b7988176729a89eaa5489d0be83e75a8655c16029ecd956665fc86f00e68bad |
Hashes for autopy-3.1.0-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | eaf793f0f0a40bd695a47279026872798e21ef05d6461ba0e63c416c8564ed49 |
|
MD5 | e7d245847ac7b0645844a3f3667fa794 |
|
BLAKE2b-256 | 99f07eb274fc30e3a5faf42c028477e5e32e3d2834fe535d9784bcbe629e6842 |
Hashes for autopy-3.1.0-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 634678d1d6e09e06de2820da582d04c18ed63396b76c9aa0e50d1605e7d60986 |
|
MD5 | e9c985f7b78a869dfb0a20e084c78299 |
|
BLAKE2b-256 | 0e3c303249be3c6f45caa6c1d592d4ffee87337294f8e2e1496c0515787af8ea |
Hashes for autopy-3.1.0-cp35-cp35m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 10c5cca76f47c61b2f458ae634de1c238dcbde3140d67fa0dcde9473fae47dc6 |
|
MD5 | b39365f488685fff66bdc6725c0ea199 |
|
BLAKE2b-256 | 34018522fbaa3af33fdacfa7c80292a4b397a70c405049735e49b4eafe39eee3 |
Hashes for autopy-3.1.0-cp35-cp35m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a6b5684b24ee4ff59248068d9559aaa70a6dada4ba4fb4901218126ea9a8994 |
|
MD5 | 9a00bf2be05e3f6e83ce66caeec0112f |
|
BLAKE2b-256 | 00733a13d45dea1f0df550acff293730781f978cad44cc8c355340c855af0d44 |
Hashes for autopy-3.1.0-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a2d834799221b515a974569e1d568577da04551404623bd3360259b52d46ff0 |
|
MD5 | 237074c921c0a0b5030cefcd1955d216 |
|
BLAKE2b-256 | 15f9421a5c0c120f5833bf79a7a1fc6901ea4c2c088bb89e70a5875c8af77734 |
Hashes for autopy-3.1.0-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b13d05a44b3141cf3900c5bfaa5d04b0b5e409d2eafa0f36017c963d5414f09 |
|
MD5 | 9e0f356a249bb4aa8127589446b09d3a |
|
BLAKE2b-256 | ffc74d030548b37335946e2c30489de4589744a0352fc887f5c820ae62fabe80 |
Hashes for autopy-3.1.0-cp35-cp35m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1b25e0ce8d1f4c99114758305e9a2521a4d5e01afeed673a2d9dd60f90f585a3 |
|
MD5 | 5e1ad84672e7720dcc9229e9c8e073f1 |
|
BLAKE2b-256 | eca418a992857a8d7d4664b5bd2481e52a5e7627eb90e57d82c741f2a83ce4ba |
Hashes for autopy-3.1.0-cp27-cp27mu-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2fc7f0713063667e4d4bcf8d650ad53d11b3d4841cfc2e5d0d69d357eb46370 |
|
MD5 | 002a386dd820a75d1622a7fa0012d068 |
|
BLAKE2b-256 | b2299ddf1cd31587ffdf5fbe5b9d4afced28fbabe8dfc3774b254e792f3a61af |
Hashes for autopy-3.1.0-cp27-cp27mu-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6626d9f093956395b5771ca9e742df75fef42d2b22aded6021481aa4092ba061 |
|
MD5 | cff0ae69123c8ec39206acf626f1dcf2 |
|
BLAKE2b-256 | 28bc6f930b9db3992e49dd4cb1489d7be7164e2755d595d66c205d13b19decd2 |
Hashes for autopy-3.1.0-cp27-cp27mu-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 067430115f4df9aacece8d0c59aea5b5e53613a83044895f55fdc5af6368fa00 |
|
MD5 | 637a9702c272d1a6d0ee83cdfd4e9613 |
|
BLAKE2b-256 | 7f8cf65ac6d9482b1c7498c8892e0f0903b24bb1c91681f57da73a0396256a1a |
Hashes for autopy-3.1.0-cp27-cp27mu-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0cd1ee833f51fee5f735948a612c7324a6c8dd540b51f5864fec87691047c2f |
|
MD5 | 6862070a32df851fc5af7b1c2ef82237 |
|
BLAKE2b-256 | ce5abe26e41d195d620fd144559cab0ecc087b79e4101eada3836faeaf2461ad |
Hashes for autopy-3.1.0-cp27-cp27m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7aea30f15852d54ea3b1abb929f00f1ec015eec6997fa296d5685bc53cdb14f4 |
|
MD5 | 7ca2ba3be0a3c973bd3493ce771b8a08 |
|
BLAKE2b-256 | d979fc71a8057c0df2e3d1af2107c842729727f9fa4ba0da7b743db02f0e0b01 |
Hashes for autopy-3.1.0-cp27-cp27m-manylinux2010_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d288aba9e3cca105bb6cf009f15c1b6baf8c835601029986f9dbcf5ad9ad38b9 |
|
MD5 | 60778d9ea368531908b9249d659188e3 |
|
BLAKE2b-256 | e9aba6b6aa20e20d9f12d53bd5356ce059016a92692edaf33a2a260e6b8a8500 |
Hashes for autopy-3.1.0-cp27-cp27m-manylinux2010_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1f5e76f35c2766b2e85633140db3dabc1cf7aa765e3851331b1bd9b262306119 |
|
MD5 | bd5b3141311f18a0fe9ffe32cb58640f |
|
BLAKE2b-256 | 86f1b96d2348fbc4697365ab0c5844929a0a768f7518ad4343376f6f91449048 |
Hashes for autopy-3.1.0-cp27-cp27m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 13e740e7731d666513f60a675268c724e31c4de9c0baf8b576f915707c6df361 |
|
MD5 | 89259b8e5b1607977b2fec700d8dd53e |
|
BLAKE2b-256 | 249dd83a8850f0f70a9bb365a27971cf642100a56e94c39a5147f8646deb4d80 |
Hashes for autopy-3.1.0-cp27-cp27m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c253fbfc2f0e2f777184638800798102cde910a2e7e894e6372627f55cccdaf3 |
|
MD5 | 00a59d8c53347e63d3eec6cd08fd32d7 |
|
BLAKE2b-256 | 3ebb623fe7047ba2eab0493ff3d22f97d62d5d6f14a9e65ce3bc455b49037d85 |
Hashes for autopy-3.1.0-cp27-cp27m-macosx_10_6_intel.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ae8c4e4ef27d6d2af14558518e18d930b23547a6b2ce6562b92fdfc52905941 |
|
MD5 | 514f48f627f382c588a8469a9246def9 |
|
BLAKE2b-256 | 594769f9475d720325469eae79823fee60af354b5b9e2a802277c1c5ecdd2a83 |