PyMobileDevice3
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
- breaking For iOS 17.0 and later, developer services require tunnel-based transport (e.g., `tunneld` or `start-tunnel`) due to Apple's new CoreDevice framework. Direct connections to developer services will fail without a tunnel.
- breaking The CLI command `start-quic-tunnel` was renamed to `start-tunnel` (e.g. for creating developer tunnels). Scripts using the old command will break.
- gotcha Platform-specific external dependencies are required for PyMobileDevice3 to function. Windows users need iTunes, Linux users need `usbmuxd`, and for Recovery/DFU mode or older iOS versions, `libusb` and `OpenSSL` might be necessary.
- gotcha When bundling PyMobileDevice3 into an executable (e.g., using PyInstaller), there can be a significant performance overhead and startup delay (up to 10 seconds or more) compared to running directly from an installed Python environment.
Install
-
pip install -U pymobiledevice3
Imports
- create_using_usbmux
from pymobiledevice3.lockdown import create_using_usbmux
- SyslogService
from pymobiledevice3.services.syslog import SyslogService
- LockdownClient
from pymobiledevice3.lockdown import LockdownClient
Quickstart
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())