Skip to content

Android Debug Bridge (ADB) basic wrapper in Python, with timeout support in case of long operations

License

Notifications You must be signed in to change notification settings

ClaudiuGeorgiu/PythonADB

Repository files navigation

PythonADB

Android Debug Bridge (ADB) wrapper in Python.

Codacy Ubuntu Build Status Windows Build Status MacOS Build Status Code Coverage Python Version License

This project contains a basic Python wrapper of the command line adb (Android Debug Bridge) tool (by using the subprocess module in Python). Currently, the main functions are supported (shell commands, file copy operations and app installations) but the wrapper is easily extensible with new features. All the implemented functions support an optional timeout value (tested on Ubuntu, Windows and MacOS) to let the command fail if it takes too long to finish execution (this can be useful during automatic testing).

❱ Prerequisites

This project is only a wrapper of ADB, so adb should be already installed and working. In order to test if you have a working adb installation, you can run the following command in a terminal:

$ adb version
Android Debug Bridge version 1.0.41
...

If adb is installed in a custom location, ADB_PATH environment variable can be used to specify the adb executable to be used by PythonADB (e.g., in Ubuntu, run export ADB_PATH=/custom/location/adb before running PythonADB in the same terminal).

❱ Usage

Apart from ADB, the only requirement of this project is a working Python 3 (at least 3.8) installation. The first thing to do is to get a local copy of this repository, so open up a terminal in the directory where you want to save the project and clone the repository:

$ git clone https://github.com/ClaudiuGeorgiu/PythonADB.git

Run the following commands in the main directory of the project (PythonADB/) to install the needed dependencies:

$ # Make sure to run the commands in PythonADB/ directory.

$ # The usage of a virtual environment is highly recommended.
$ python3 -m venv venv
$ source venv/bin/activate

$ # Install PythonADB's requirements.
$ python3 -m pip install -r requirements.txt

Usage example (see start.py file for a complete example):

from adb.adb import ADB

adb = ADB()
adb.get_version()
adb.wait_for_device()
adb.shell(["ls"])
# The following commands will fail if not completed in 30 seconds.
adb.install_app("/path/to/file.apk", timeout=30)
adb.pull_file("/path/on/device", "/path/on/host", timeout=30)
# ... more ...

See adb/adb.py file for a complete list with all the implemented adb commands.

❱ Contributing

Questions, bug reports and pull requests are welcome on GitHub at https://github.com/ClaudiuGeorgiu/PythonADB.

❱ License

You are free to use this code under the MIT License.

About

Android Debug Bridge (ADB) basic wrapper in Python, with timeout support in case of long operations

Topics

Resources

License

Stars

Watchers

Forks

Languages