Mozdevice (Mozilla Device Management)

4.2.0 · active · verified Thu Apr 16

Mozdevice is a Python library developed by Mozilla for managing and interacting with mobile devices (Android, Firefox OS/B2G) via ADB, as well as desktop browsers. It provides functionalities for device introspection, application management, and remote command execution, primarily used in automated testing and development workflows. The current version is 4.2.0, with an active release cadence driven by Mozilla's mobile testing needs. It requires Python 3.6 or newer.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart connects to a locally available Android device via ADB, retrieves basic device information, and lists installed packages. Ensure ADB (Android Debug Bridge) is installed and configured in your system's PATH, and a device is connected and authorized.

import os
from mozdevice.devicemanager import DeviceManager

try:
    # Connect to a locally available ADB device
    # If multiple devices are connected, you might need to specify 'serial'
    dm = DeviceManager()
    print(f"Connected to device: {dm.name}")
    print(f"Device type: {dm.device_type}")
    print(f"Device OS: {dm.os}")

    # Example: Get a list of installed packages (Android)
    if dm.os == 'android':
        packages = dm.list_packages()
        print(f"Number of installed packages: {len(packages)}")
        # print(f"Sample packages: {packages[:5]}")

except Exception as e:
    print(f"Error connecting or interacting with device: {e}")
    print("Please ensure ADB is installed and a device is connected and authorized.")

view raw JSON →