Pure python implementation of the adb client
Project description
This is pure-python implementation of the ADB client.
You can use it to communicate with adb server (not the adb daemon on the device/emulator).
Installation
$pip install -U pure-python-adb
Examples
Connect to adb server and get the version
from adb.client import Client as AdbClient
# Default is "127.0.0.1" and 5037
client = AdbClient(host="127.0.0.1", port=5037)
print(client.version())
>>> 39
Connect to a device
from adb.client import Client as AdbClient
# Default is "127.0.0.1" and 5037
client = AdbClient(host="127.0.0.1", port=5037)
device = client.device("emulator-5554")
List all devices ( adb devices ) and install/uninstall an APK on all devices
from adb.client import Client as AdbClient
apk_path = "example.apk"
# Default is "127.0.0.1" and 5037
client = AdbClient(host="127.0.0.1", port=5037)
devices = client.devices()
for device in devices:
device.install(apk_path)
# Check apk is installed
for device in devices:
print(device.is_installed("example.package"))
# Uninstall
for device in devices:
device.uninstall("example.package)
adb shell
from adb.client import Client as AdbClient
# Default is "127.0.0.1" and 5037
client = AdbClient(host="127.0.0.1", port=5037)
device = client.device("emulator-5554")
device.shell("echo hello world !")
def dump_logcat(connection):
while True:
data = connection.read(1024)
if not data:
break
print(data.decode('utf-8')))
connection.close()
from adb.client import Client as AdbClient
# Default is "127.0.0.1" and 5037
client = AdbClient(host="127.0.0.1", port=5037)
device = client.device("emulator-5554")
device.shell("logcat", handler=dump_logcat)
Screenshot
from adb.client import Client as AdbClient
client = AdbClient(host="127.0.0.1", port=5037)
device = client.device("emulator-5554")
result = device.screencap()
with open("screen.png", "wb") as fp:
fp.write(result)
Push
from adb.client import Client as AdbClient
client = AdbClient(host="127.0.0.1", port=5037)
device = client.device("emulator-5554")
device.push("example.apk", "/sdcard/example.apk")
Pull
from adb.client import Client as AdbClient
client = AdbClient(host="127.0.0.1", port=5037)
device = client.device("emulator-5554")
device.shell("screencap -p /sdcard/screen.png")
device.pull("/sdcard/screen.png", "screen.png")
1.0.0 (2018-06-23)
First release on PyPI.
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
pure-python-adb-0.1.4.dev0.tar.gz
(12.2 kB
view hashes)
Close
Hashes for pure-python-adb-0.1.4.dev0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c370b458aea065ab4a490f357f1d58382f84556213b8e65b96adfe9b74487e6 |
|
MD5 | 8f5e2d6bbc903294d9fa2317977a9740 |
|
BLAKE2b-256 | fee9d58d1d74568d2a9c46c05f78f8a82ed8cd9f8ae1149df4959137c5b2ce05 |