adb_shell
raw JSON → 0.4.4 verified Mon Apr 27 auth: no python
A Python implementation of ADB with shell and FileSync functionality. Current version 0.4.4, somewhat irregular release cadence.
pip install adb-shell Common errors
error ModuleNotFoundError: No module named 'adb_shell' ↓
cause Package not installed or installed with wrong name.
fix
Run
pip install adb-shell (the package name on PyPI is adb-shell, not adb_shell). error AttributeError: module 'adb_shell' has no attribute 'AdbDeviceTcp' ↓
cause Incorrect import path; AdbDeviceTcp is in adb_device submodule.
fix
Use
from adb_shell.adb_device import AdbDeviceTcp. error ConnectionRefusedError: [Errno 111] Connection refused ↓
cause ADB server not running or device not connected on the specified host/port.
fix
Ensure ADB server is running (
adb start-server) and device is connected (adb devices). Verify host and port (default 5555). Warnings
gotcha Importing from adb_shell directly (e.g., `from adb_shell import AdbDeviceTcp`) raises ImportError. Always import from the submodule `adb_shell.adb_device`. ↓
fix Use `from adb_shell.adb_device import AdbDeviceTcp`.
gotcha The `close()` method must be called after finishing to release transport resources. Failing to do so may cause resource leaks. ↓
fix Always call `device.close()` or use a context manager (if available).
Imports
- AdbDeviceTcp wrong
from adb_shell import AdbDeviceTcpcorrectfrom adb_shell.adb_device import AdbDeviceTcp - AdbDeviceUsb wrong
from adb_shell.adb_device import AdbDeviceUsbcorrectfrom adb_shell.adb_device import AdbDeviceUsb - AdbCommands wrong
from adb_shell import AdbCommandscorrectfrom adb_shell.adb_device import AdbCommands
Quickstart
from adb_shell.adb_device import AdbDeviceTcp
from adb_shell.auth.sign_pythonrsa import PythonRSASigner
# Load the RSA key pair (usually from ~/.android/adbkey and adbkey.pub)
with open('~/.android/adbkey', 'r') as f:
priv = f.read()
with open('~/.android/adbkey.pub', 'r') as f:
pub = f.read()
signer = PythonRSASigner(pub, priv)
device = AdbDeviceTcp('localhost', 5555)
device.connect(rsa_keys=[signer], auth_timeout_s=10)
print(device.shell('echo hello'))
device.close()