You can do it with AndroidViewClient/culebra.

Here is an example you can base your script on (autogenerated by culebra):

#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (C) 2013-2018  Diego Torres Milano
Created on 2018-08-09 by Culebra v15.4.0
                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
"""


import re
import sys
import os


import unittest

from com.dtmilano.android.viewclient import ViewClient, CulebraTestCase

TAG = 'CULEBRA'


class CulebraTests(CulebraTestCase):

    @classmethod
    def setUpClass(cls):
        cls.kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
        cls.kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'debug': {}, 'startviewserver': True, 'compresseddump': True}
        cls.options = {'start-activity': None, 'concertina': False, 'device-art': None, 'use-jar': False, 'multi-device': False, 'unit-test-class': True, 'save-screenshot': None, 'use-dictionary': False, 'glare': False, 'dictionary-keys-from': 'id', 'scale': 0.5, 'find-views-with-content-description': True, 'window': -1, 'orientation-locked': None, 'concertina-config': None, 'save-view-screenshots': None, 'find-views-by-id': True, 'log-actions': False, 'use-regexps': False, 'null-back-end': False, 'auto-regexps': None, 'do-not-verify-screen-dump': True, 'verbose-comments': False, 'gui': True, 'find-views-with-text': True, 'prepend-to-sys-path': False, 'install-apk': None, 'drop-shadow': False, 'output': 'aonoff.py', 'unit-test-method': None, 'interactive': False}
        cls.sleep = 5

    def setUp(self):
        super(CulebraTests, self).setUp()

    def tearDown(self):
        super(CulebraTests, self).tearDown()

    def preconditions(self):
        if not super(CulebraTests, self).preconditions():
            return False
        return True

    def testSomething(self):
        if not self.preconditions():
            self.fail('Preconditions failed')

        _s = CulebraTests.sleep
        _v = CulebraTests.verbose

        self.vc.dump(window=-1)
        self.vc.uiDevice.openQuickSettings()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)
        self.vc.findViewWithContentDescriptionOrRaise(u'''Airplane mode''').touch()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)
        self.device.press('KEYCODE_BACK')
        self.device.press('KEYCODE_BACK')

        print >> sys.stderr, 'Now Airplane mode is ON, switching it back to OFF'
        self.vc.sleep(5)

        self.vc.uiDevice.openQuickSettings()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)
        self.vc.findViewWithContentDescriptionOrRaise(u'''Airplane mode''').touch()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)
        self.device.press('KEYCODE_BACK')
        self.device.press('KEYCODE_BACK')


if __name__ == '__main__':
    CulebraTests.main()
Answer from Diego Torres Milano on Stack Overflow
🌐
ITNEXT
itnext.io › how-you-can-control-your-android-device-with-python-45c3ab15e260
How you can Control your Android Device with Python | by Kush | ITNEXT
April 15, 2021 - In this quick guide I will show you how you can interface with it using Python and how to create 2 quick scripts. The ADB (Android Debug Bridge) is a command line tool (CLI) which can be used to control and communicate with an Android device.
🌐
DEV Community
dev.to › petercour › automate-android-with-python-14j0
Automate Android with Python - DEV Community
July 4, 2019 - To do so, adb must be installed and the phone connected. Then you can use adb shell commands to control the phone like · #!/usr/bin/python3 import os ... os.system("adb shell input tap 350 715") which will click on the screen.
Discussions

How to control an android phone using python?
Well done 👍🏼 More on reddit.com
🌐 r/Python
1
13
October 3, 2021
control android device/emulator by python - Stack Overflow
I am not familiar with android development. But just want to use python script to do something on my android device/emulator. For example: change system settings. set a proxy. open app A, click some More on stackoverflow.com
🌐 stackoverflow.com
Looking to automate an Android app using Python - advice on where to begin?

Android studios emulator is pretty good nowadays, but very likely the best you could do is use Python to trigger touch events. You won't likely be able to interface directly with the app to do things like trades. Android is pretty good at not letting apps inject touch events and could cause security exceptions. Something as small as rext input would very likely entirely break any attempt to try to do an Android only solution. That being said, if the app exposes intents to do things like trading you could very easily use adb or an app to trigger them, but it seems unlikely that a stock trade app would expose those intents.

More on reddit.com
🌐 r/learnpython
18
29
June 1, 2016
How to control android device using appium and python? - Stack Overflow
I have tried many examples but ... and then controlling it using touches and keypress. I am not looking for an app testing instead I am looking for an android device testing using resorce id ,name,class or xpath. ... Not sure about appium, but AndroidViewClient/culebra can easily do what you want. Install it, run culebra with or without GUI (-G) and you will be able to automatically generate python tests or plain ... More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 1
2

You can do it with AndroidViewClient/culebra.

Here is an example you can base your script on (autogenerated by culebra):

#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (C) 2013-2018  Diego Torres Milano
Created on 2018-08-09 by Culebra v15.4.0
                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
"""


import re
import sys
import os


import unittest

from com.dtmilano.android.viewclient import ViewClient, CulebraTestCase

TAG = 'CULEBRA'


class CulebraTests(CulebraTestCase):

    @classmethod
    def setUpClass(cls):
        cls.kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
        cls.kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'debug': {}, 'startviewserver': True, 'compresseddump': True}
        cls.options = {'start-activity': None, 'concertina': False, 'device-art': None, 'use-jar': False, 'multi-device': False, 'unit-test-class': True, 'save-screenshot': None, 'use-dictionary': False, 'glare': False, 'dictionary-keys-from': 'id', 'scale': 0.5, 'find-views-with-content-description': True, 'window': -1, 'orientation-locked': None, 'concertina-config': None, 'save-view-screenshots': None, 'find-views-by-id': True, 'log-actions': False, 'use-regexps': False, 'null-back-end': False, 'auto-regexps': None, 'do-not-verify-screen-dump': True, 'verbose-comments': False, 'gui': True, 'find-views-with-text': True, 'prepend-to-sys-path': False, 'install-apk': None, 'drop-shadow': False, 'output': 'aonoff.py', 'unit-test-method': None, 'interactive': False}
        cls.sleep = 5

    def setUp(self):
        super(CulebraTests, self).setUp()

    def tearDown(self):
        super(CulebraTests, self).tearDown()

    def preconditions(self):
        if not super(CulebraTests, self).preconditions():
            return False
        return True

    def testSomething(self):
        if not self.preconditions():
            self.fail('Preconditions failed')

        _s = CulebraTests.sleep
        _v = CulebraTests.verbose

        self.vc.dump(window=-1)
        self.vc.uiDevice.openQuickSettings()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)
        self.vc.findViewWithContentDescriptionOrRaise(u'''Airplane mode''').touch()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)
        self.device.press('KEYCODE_BACK')
        self.device.press('KEYCODE_BACK')

        print >> sys.stderr, 'Now Airplane mode is ON, switching it back to OFF'
        self.vc.sleep(5)

        self.vc.uiDevice.openQuickSettings()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)
        self.vc.findViewWithContentDescriptionOrRaise(u'''Airplane mode''').touch()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)
        self.device.press('KEYCODE_BACK')
        self.device.press('KEYCODE_BACK')


if __name__ == '__main__':
    CulebraTests.main()
🌐
Dustingram
dustingram.com › articles › 2010 › 06 › 18 › automated-control-of-an-android-device-with-python
Automated Control of an Android Device with Python - Dustin Ingram
June 18, 2010 - Using Android's Simple Protocol for Automated Network Control to send touch events to a physical device using Python and a TCP socket.
🌐
GitHub
github.com › BennbuildVGC › android_controller
GitHub - BennbuildVGC/android_controller: A python module to control your android phone · GitHub
A python module to control your android phone · Pip · adb installed and added to PATH · Open a command prompt and run: pip install android_controller · Open a command promp and clone this repo.
Starred by 23 users
Forked by 8 users
Languages   Python
🌐
Reddit
reddit.com › r/python › how to control an android phone using python?
r/Python on Reddit: How to control an android phone using python?
October 3, 2021 -

Controlling Android Phone using Python

I have recently posted my first blog on dev.to. In the blog, I talked about how one can control a mobile phone using python and do multiple tasks like sending WhatsApp messages, calling, screen recording, opening apps and URLs etc.

Here is the link for that: https://dev.to/yash_makan/controlling-mobile-phone-using-python-192o

Find elsewhere
🌐
Pythonmana
pythonmana.com › 2021 › 07 › 20210731153205519F.html
Control your Android phone with Python - Python知识
July 31, 2021 - You can use pip install pure-python-adb install pure-python-adb library . Optional : To make it easier for us to develop scripts , We can install one called scrcpy Open source program for , The program allows us to use the mouse and keyboard to display and control our...
🌐
Dormoshe
dormoshe.io › trending-news › how-you-can-control-your-android-device-with-python-28123
How you can Control your Android Device with Python
A while back I was thinking of ways in which I could annoy my friends by spamming them with messages for a few minutes, and while doing some research I came across the Android Debug Bridge. In this...
🌐
Reddit
reddit.com › r/learnpython › looking to automate an android app using python - advice on where to begin?
r/learnpython on Reddit: Looking to automate an Android app using Python - advice on where to begin?
June 1, 2016 -

I've been using Robinhood to invest and am trying to write an automated trading algorithm. Unfortunately, Robinhood is only on Android and doesn't have access to an API for automated trading.

I just had the idea that Android apps can probably be emulated on PC, right? So I'm looking for both:

1) An Android app emulator on PC (free is best but I'll pay for performance if it's necessary)

2) A Python library for automating Android apps on that emulator. I'm thinking Selenium, but for Android infrastructure.

Has anyone had any experience doing this before? Thank you so much!

Edit: Just wanted to clarify that I originally tried Quantopian because that seemed like the perfect solution. Unfortunately, my strategy is a timing strategy and Quantopian only allows the import of external data once a day via CSV.

🌐
PyPI
pypi.org › project › android-controller
android-controller
August 3, 2020 - JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
Top answer
1 of 2
1

Not sure about appium, but AndroidViewClient/culebra can easily do what you want.

Install it, run culebra with or without GUI (-G) and you will be able to automatically generate python tests or plain scripts.

For example, if you run

$ culebra -GuU --scale=0.5 -o chrome.py

while the device is on the home screen and click the Chrome icon to open it, this script will be generated

#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""
Copyright (C) 2013-2018  Diego Torres Milano
Created on 2018-04-04 by Culebra v15.1.2
                      __    __    __    __
                     /  \  /  \  /  \  /  \ 
____________________/  __\/  __\/  __\/  __\_____________________________
___________________/  /__/  /__/  /__/  /________________________________
                   | / \   / \   / \   / \   \___
                   |/   \_/   \_/   \_/   \    o \ 
                                           \_____/--<
@author: Diego Torres Milano
@author: Jennifer E. Swofford (ascii art snake)
"""


import re
import sys
import os


import unittest

from com.dtmilano.android.viewclient import ViewClient, CulebraTestCase

TAG = 'CULEBRA'


class CulebraTests(CulebraTestCase):

    @classmethod
    def setUpClass(cls):
        cls.kwargs1 = {'ignoreversioncheck': False, 'verbose': False, 'ignoresecuredevice': False}
        cls.kwargs2 = {'forceviewserveruse': False, 'useuiautomatorhelper': False, 'ignoreuiautomatorkilled': True, 'autodump': False, 'startviewserver': True, 'compresseddump': True}
        cls.options = {'start-activity': None, 'concertina': False, 'device-art': None, 'use-jar': False, 'multi-device': False, 'unit-test-class': True, 'save-screenshot': None, 'use-dictionary': False, 'glare': False, 'dictionary-keys-from': 'id', 'scale': 0.5, 'find-views-with-content-description': True, 'window': -1, 'orientation-locked': None, 'concertina-config': None, 'save-view-screenshots': None, 'find-views-by-id': True, 'log-actions': False, 'use-regexps': False, 'null-back-end': False, 'auto-regexps': None, 'do-not-verify-screen-dump': True, 'verbose-comments': False, 'gui': True, 'find-views-with-text': True, 'prepend-to-sys-path': False, 'install-apk': None, 'drop-shadow': False, 'output': 'chrome.py', 'unit-test-method': None, 'interactive': False}
        cls.sleep = 5

    def setUp(self):
        super(CulebraTests, self).setUp()

    def tearDown(self):
        super(CulebraTests, self).tearDown()

    def preconditions(self):
        if not super(CulebraTests, self).preconditions():
            return False
        return True

    def testSomething(self):
        if not self.preconditions():
            self.fail('Preconditions failed')

        _s = CulebraTests.sleep
        _v = CulebraTests.verbose

        self.vc.dump(window=-1)
        self.vc.findViewWithContentDescriptionOrRaise(u'''Chrome''').touch()
        self.vc.sleep(_s)
        self.vc.dump(window=-1)


if __name__ == '__main__':
    CulebraTests.main()

then you can run it as

$ ./chrome.py

to achieve the same at any time

2 of 2
0

I think the problem is like mine...want to control an android device or emulator with Appium, may be Mayank Shivhare already try to learn culebra and found the fact that....culebra is still not support by python 3 yet (same problem like me that prefer python 3.7 than python 2.7).

I have the same problem..., what I understood right now is:

  1. All environment should be set up first

  2. The emulator should be run first...before type any code

  3. then run Appium to make a gateway with IP and port.

  4. the missing link is how to connect an emulator to appium via ip and port that provide by appium server.

  5. I can detect the emulator element by run 'uiautomatorviewer.bat' from sdk\tools\bin folder, the problem is the problem in number 3, is how to send a command to the emulator via appium. so the command to control emulator base on data that given by 'uiautomatorviewer.bat'

coding is about trial and error, so we need live interaction, to build source code. every developer has a personal interest in build a script or source code. so..to make easier, as beginner, we need live interaction that shows every error in every step our script or to make sure that every line of our script that we type is run smoothly in the android device or emulator.

The problem in learn appium is all manual already given finished script...without a really-really basic explanation...in my case, how to connect appium to emulator, send a command from python console, and see the script is work or not...

what I mean is... we need the step by step explanation of script...because every beginner developers need a live 'trial and error' experience to understand how it works...

🌐
GitHub
github.com › nladuo › PyAndroidControl
GitHub - nladuo/PyAndroidControl: Your Remote ADB controller. Control your Android device via python scripts.
Control your Android device via python scripts. Install PyAndroidControl App, and make sure the App has Root Permission. Change the simple-control-server/logics.py to what ever you want. def get_commands(token, img_file): """ analyze the screenshot ...
Starred by 90 users
Forked by 22 users
Languages   Kotlin 70.4% | Python 29.6% | Kotlin 70.4% | Python 29.6%
🌐
Technolabsz
technolabsz.com › 2012 › 11 › controlling-android-phones-using-python.html
TechnoLabsz: Controlling Android Phones using Python and Linux
November 4, 2012 - Hi all I am giving a brief tutorial on how to control android phone using python over wifi using PC. Prerequisites on an...
🌐
Toptal
toptal.com › android › control-your-laptop-with-android-python-twisted-and-django
Control Your Laptop with an Android Phone using Python, Twisted, and Django | Toptal®
January 31, 2023 - Once you have your interpreter setup, you can do basically whatever you like by combining Python with the Android API, including controlling your laptop remotely.
🌐
Raspberry Pi Forums
forums.raspberrypi.com › board index › programming › python
Control Android Phone with Python - Raspberry Pi Forums
My plan is to connect an Android phone with USB to my raspberry. I would like to control the mobile phone with a Python script, specifically I would like to trigger the camera. I don't want to have a python script on the phone itself, just on the raspberry. I couldn't find something similar to this.
🌐
Stack Overflow
stackoverflow.com › questions › 37203580 › control-android-phone-by-python
Control Android phone by Python - Stack Overflow
May 13, 2016 - Phone should not be rooted, i know through adb if the phone is rooted we can connect. But I need a solution without the phone being rooted ... Why do you want to do this via Python specifically? Could look at WiFiManager to do this in a traditional Java/Android application
🌐
Analytics Vidhya
analyticsvidhya.com › home › python in android: bringing python power to mobile apps
Python in Android: Bringing Python Power to Mobile Apps
February 27, 2025 - SL4A provides access to Android APIs using high-level Python scripts, enabling automation tasks without writing a full-fledged Android app. ... Automating Device Functions: Python scripts can automate various device functionalities like taking ...
🌐
Medium
medium.com › @dhadiprasetyo › android-app-automation-complete-guide-with-python-3-appium-2-and-android-emulator-for-beginner-a2f53ca60e58
Android App Automation Complete Guide With Python 3, Appium 2 and Android Emulator For Beginner | by Darmawan Hadiprasetyo | Medium
March 4, 2023 - cd /path/to/new/virtual/environment source bin/activate pip install Appium-Python-Client · Open Android Studio -> More Actions -> Virtual Device Manager -> Create device -> Choose any type of device you want (in this tutorial I use Pixel 4 ...
🌐
Pythonmana
pythonmana.com › 2021 › 10 › 20211023014835075v.html
Using Python to control your phone
October 23, 2021 - With the code above , Even if you change the position of our game on the mobile screen ,python You can still open the game . ... You can use it. adb and python Do more . Let's talk about some of them . ... def swipe( start_x, start_y, end_x, end_y, duration_ms): adb( "adb shell input swipe {} {} {} {} {}". format( start_x, start_y, end_x, end_y, duration_ms)) ... def call( number): adb( f"adb shell am start -a android.intent.action.CALL -d tel:{ number} ") call( '+91xxxxxxxxxx') # +[CODE][NUMBER]