PyMobileDevice3

9.9.1 · active · verified Wed Apr 15

PyMobileDevice3 is a pure Python 3 implementation for interacting with iOS devices (iPhone, iPad, etc.). It provides both a command-line interface (CLI) and a Python API, enabling functionalities like device discovery, TCP port forwarding, syslog streaming, application management, AFC file access, and more. The library is actively maintained with frequent releases, currently at version 9.9.1.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to connect to a USB-attached iOS device and stream its syslog using the PyMobileDevice3 Python API. It includes necessary imports and basic error handling for common setup issues. Ensure your device is connected and trusted before running.

import asyncio
import os
from pymobiledevice3.lockdown import create_using_usbmux
from pymobiledevice3.services.syslog import SyslogService

async def main():
    # This example connects to a USB-connected and trusted iOS device
    # and streams its syslog output.
    try:
        lockdown = await create_using_usbmux()
        device_name = lockdown.get_device_name()
        device_udid = lockdown.udid
        print(f"Connected to device: {device_name} (UDID: {device_udid})")

        syslog_service = SyslogService(service_provider=lockdown)
        print("\nStreaming syslog (press Ctrl+C to stop)...\n")

        async for line in syslog_service.watch():
            print(line)

    except Exception as e:
        print(f"\nError: {e}")
        print("Please ensure:")
        print("1. An iOS device is connected via USB and is trusted by your computer.")
        print("2. On Linux, 'usbmuxd' is installed and running. On Windows, iTunes is installed.")
        print("3. For older iOS versions (<13), OpenSSL is installed.")
        print("4. If accessing developer services on iOS 17+, a tunnel is established (e.g., 'sudo python3 -m pymobiledevice3 remote start-tunnel').")

if __name__ == '__main__':
    asyncio.run(main())

view raw JSON →