adb_shell_wifi
This package is a fork of adb_shell that adds support for modern ADB Wi-Fi pairing — the 6-digit-code TLS pairing flow introduced in Android 11’s “Wireless debugging” feature, plus the post-pairing TLS data channel and mDNS-based service discovery.
It exists primarily as a testbed for verifying that Wi-Fi pairing support can be added to Home Assistant’s Android TV integration. If you do not need Wi-Fi pairing, install upstream adb-shell instead — the upstream package is the canonical home of all non-Wi-Fi functionality.
Original adb_shell documentation: https://adb-shell.readthedocs.io/
Origin
This Python package implements ADB shell and FileSync functionality. It originated from python-adb and was substantially rewritten by Jeff Irion in adb_shell; this fork adds Wi-Fi pairing on top.
Installation
pip install adb-shell-wifi
Async
To utilize the async version of this code, you must install into a Python 3.7+ environment via:
pip install adb-shell-wifi[async]
USB Support (Experimental)
To connect to a device via USB, install this package via:
pip install adb-shell-wifi[usb]
Wi-Fi Pairing Support (Experimental)
To pair with a modern Android device using a 6-digit pairing code (Android 11+ “Wireless debugging”), install this package via:
pip install adb-shell-wifi[wifi]
This pulls in spake2-cffi and pyOpenSSL. Note: spake2-cffi does not publish Windows wheels, so Windows users will need a C toolchain available at install time.
On the device, open Settings > System > Developer options > Wireless debugging > Pair device with pairing code. Note the IP address, port, and 6-digit code shown by the device, then:
from adb_shell_wifi.pairing import pair
adbkey = "path/to/adbkey"
with open(adbkey, "rb") as f:
priv = f.read()
with open(adbkey + ".pub", "rb") as f:
pub = f.read()
peer_info = pair(
host="192.168.1.42", # from device UI
port=43811, # from device UI
pairing_code="515109", # from device UI
private_key_pem=priv,
public_key=pub,
)
print("device peer info:", peer_info.type, peer_info.data)
After pairing succeeds, the device records the host’s public key in its keystore. To actually run shell commands, push, pull, etc. over the post-pairing TLS channel, use AdbDeviceTls and pass the same adbkey PEM as tls_priv_pem:
from adb_shell_wifi.adb_device import AdbDeviceTls
from adb_shell_wifi.mdns import discover_connect_services
# Find the random port the device chose for its TLS data socket.
services = discover_connect_services(timeout_s=4.0)
svc = services[0] # or pick the right device by name/host
device = AdbDeviceTls(svc.host, svc.port, default_transport_timeout_s=10.0)
device.connect(rsa_keys=[], tls_priv_pem=priv, auth_timeout_s=10.0)
print(device.shell("echo hello from adb_shell_wifi"))
device.close()
The mdns module also exposes discover_pairing_services() for finding devices that currently have a pairing dialog open, plus async equivalents (discover_connect_services_async, discover_pairing_services_async).
Example Usage
(Based on androidtv/adb_manager.py)
from adb_shell_wifi.adb_device import AdbDeviceTcp, AdbDeviceUsb
from adb_shell_wifi.auth.sign_pythonrsa import PythonRSASigner
# Load the public and private keys
adbkey = 'path/to/adbkey'
with open(adbkey) as f:
priv = f.read()
with open(adbkey + '.pub') as f:
pub = f.read()
signer = PythonRSASigner(pub, priv)
# Connect
device1 = AdbDeviceTcp('192.168.0.222', 5555, default_transport_timeout_s=9.)
device1.connect(rsa_keys=[signer], auth_timeout_s=0.1)
# Connect via USB (package must be installed via `pip install adb-shell-wifi[usb])`
device2 = AdbDeviceUsb()
device2.connect(rsa_keys=[signer], auth_timeout_s=0.1)
# Send a shell command
response1 = device1.shell('echo TEST1')
response2 = device2.shell('echo TEST2')
Generate ADB Key Files
If you need to generate a key, you can do so as follows.
from adb_shell_wifi.auth.keygen import keygen
keygen('path/to/adbkey')
Metadata
Release files for adb-shell-wifi 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| adb_shell_wifi-0.5.0.tar.gz | 86.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| adb_shell_wifi-0.5.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 165.2 kB
Release files / adb_shell_wifi-0.5.0.tar.gz
| Download URL | adb_shell_wifi-0.5.0.tar.gz |
|---|---|
| Size | 86.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
077ddccc63a1ba7350af9858dddd97b1f6e3e6ecf5030e0d4e7dc052b2561afe
|
|
BLAKE2b-256 checksum How to use checksums |
d3a7e53a81641c1ee5a5f4a512127a16b2f568400e65c0bad14322d3c40e5edd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / adb_shell_wifi-0.5.0-py3-none-any.whl
| Download URL | adb_shell_wifi-0.5.0-py3-none-any.whl |
|---|---|
| Size | 78.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
231d4c608f2631ddb2df55bdc7ea111c43275277d04fcbc791f8b613dfaa391a
|
|
BLAKE2b-256 checksum How to use checksums |
b2396685726ea605ed2d6d73d198973cf97a40e9d401b6d9eec77e3120498430
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for adb-shell-wifi 0.5.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.