System & device services¶
Services for device state, activation, notifications, power, and recovery.
pymobiledevice3.services.amfi.AmfiService ¶
Control Developer Mode on the device through the AMFI (Apple Mobile File Integrity) lockdown service.
Each method opens its own connection to the com.apple.amfi.lockdown service and sends a single
action request. The actions correspond to revealing the Developer Mode toggle in Settings,
requesting that it be enabled, and confirming the post-restart prompt.
Source code in pymobiledevice3/services/amfi.py
reveal_developer_mode_option_in_ui
async
¶
Make the Developer Mode toggle visible in the device's Settings UI.
Sends the reveal action, which causes AMFI to create an empty file at its
AMFIShowOverridePath.
Raises:
| Type | Description |
|---|---|
PyMobileDevice3Exception
|
if the device does not report success. |
Source code in pymobiledevice3/services/amfi.py
enable_developer_mode
async
¶
Request that Developer Mode be enabled on the device.
Sends the enable action. The device then reboots to apply the change. When
enable_post_restart is True, this method keeps the connection alive via a heartbeat,
waits for the device to disconnect and reconnect over usbmux, and then answers the
post-restart confirmation prompt by calling enable_developer_mode_post_restart.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enable_post_restart
|
when True, wait for the device to restart and automatically confirm the final prompt; when False, return immediately after the enable request. |
True
|
Raises:
| Type | Description |
|---|---|
DeviceHasPasscodeSetError
|
if the device has a passcode set, which blocks the operation. |
AmfiError
|
if AMFI returns any other error. |
DeveloperModeError
|
if the enable or post-restart confirmation request does not succeed. |
Source code in pymobiledevice3/services/amfi.py
enable_developer_mode_post_restart
async
¶
Confirm the Developer Mode prompt shown after the device restarts.
Sends the accept action, answering the post-restart confirmation prompt affirmatively.
Raises:
| Type | Description |
|---|---|
DeveloperModeError
|
if the device does not report success. |
Source code in pymobiledevice3/services/amfi.py
pymobiledevice3.services.mobile_activation.MobileActivationService ¶
Drive iOS device activation against Apple's activation servers via com.apple.mobileactivationd.
Orchestrates the full activation handshake: it gathers activation information from the device, exchanges it with Apple's activation and DRM-handshake endpoints over HTTP, optionally prompts the user for Apple ID credentials when the server requests them, and writes the resulting activation record back to the device. Both the modern session-based flow and the legacy lockdown flow are supported, with the session flow preferred when available.
A fresh lockdown service connection is opened for each request rather than reusing one, so this class does not inherit from the shared service base.
Source code in pymobiledevice3/services/mobile_activation.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 | |
state
async
¶
Return the device's current activation state.
Queries the activation daemon for the activation state, falling back to the lockdown
ActivationState value if the daemon request fails.
Returns:
| Type | Description |
|---|---|
|
the activation state (e.g. |
Source code in pymobiledevice3/services/mobile_activation.py
wait_for_activation_session
async
¶
Block until the device produces a fresh activation session handshake.
Repeatedly requests activation session info until the handshake request message changes, indicating the device is ready with a new session. Returns immediately if the device does not support the session-based flow.
Source code in pymobiledevice3/services/mobile_activation.py
activate
async
¶
Activate the device end-to-end against Apple's activation servers.
Does nothing if the device is already activated. Otherwise it collects activation info from
the device (preferring the session-based flow, including a DRM handshake with Apple when
available), posts it to the activation server, and applies the returned activation record.
If the server responds with a BuddyML form requesting Apple ID credentials, the user is
prompted interactively and the form is resubmitted. On success, the device's
ActivationStateAcknowledged value is set.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip_apple_id_query
|
bool
|
when True, do not prompt for Apple ID credentials; instead treat a credentials request as an iCloud lock and raise. |
False
|
Raises:
| Type | Description |
|---|---|
MobileActivationException
|
if the device is iCloud locked (with
|
Source code in pymobiledevice3/services/mobile_activation.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 | |
deactivate
async
¶
Deactivate the device.
Sends a DeactivateRequest to the activation daemon, falling back to the lockdown
Deactivate request if that fails.
Returns:
| Type | Description |
|---|---|
|
the response from whichever deactivation path succeeds. |
Source code in pymobiledevice3/services/mobile_activation.py
create_activation_session_info
async
¶
Request the device's session-based activation handshake info.
Sends a CreateTunnel1SessionInfoRequest to the activation daemon.
Returns:
| Type | Description |
|---|---|
|
the session info blob (the |
Raises:
| Type | Description |
|---|---|
MobileActivationException
|
if the daemon returns an error. |
Source code in pymobiledevice3/services/mobile_activation.py
create_activation_info_with_session
async
¶
Build the device's activation info from a completed DRM handshake.
Sends a CreateTunnel1ActivationInfoRequest to the activation daemon, passing the DRM
handshake response received from Apple.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handshake_response
|
the DRM handshake response content returned by Apple's server. |
required |
Returns:
| Type | Description |
|---|---|
|
the activation info blob (the |
Raises:
| Type | Description |
|---|---|
MobileActivationException
|
if the daemon returns an error. |
Source code in pymobiledevice3/services/mobile_activation.py
activate_with_lockdown
async
¶
Apply an activation record to the device using the legacy lockdown flow.
Parses the activation record, extracts the iphone-activation or device-activation
node, and submits its activation record via the lockdown Activate request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
activation_record
|
the serialized activation record returned by the activation server. |
required |
Raises:
| Type | Description |
|---|---|
MobileActivationException
|
if the activation record does not contain a recognized activation node. |
Source code in pymobiledevice3/services/mobile_activation.py
activate_with_session
async
¶
Apply an activation record to the device using the session-based flow.
Sends a HandleActivationInfoWithSessionRequest to the activation daemon, including the
activation record and, if provided, the HTTP response headers from the activation server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
activation_record
|
the activation record returned by the activation server. |
required | |
headers
|
HTTP response headers from the activation server, forwarded as
|
required |
Returns:
| Type | Description |
|---|---|
|
the daemon's response to the request. |
Source code in pymobiledevice3/services/mobile_activation.py
send_command
async
¶
Send a single command to the activation daemon over a fresh service connection.
Opens the com.apple.mobileactivationd service, sends the command (with an optional
Value), and returns the response. The connection is closed afterwards.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
the activation daemon command name. |
required |
value
|
str
|
optional value sent alongside the command; omitted when empty. |
''
|
Returns:
| Type | Description |
|---|---|
|
the daemon's response plist. |
Source code in pymobiledevice3/services/mobile_activation.py
post ¶
post(url: str, data: dict, headers: Optional[CaseInsensitiveDict[str, str]] = None) -> tuple[bytes, CaseInsensitiveDict[str]]
Perform an HTTP POST to an activation server endpoint.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url
|
str
|
the activation endpoint to post to. |
required |
data
|
dict
|
the form data or request body to send. |
required |
headers
|
Optional[CaseInsensitiveDict[str, str]]
|
optional request headers; the module's default activation headers are used when omitted. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[bytes, CaseInsensitiveDict[str]]
|
a tuple of the response body bytes and the response headers. |
Source code in pymobiledevice3/services/mobile_activation.py
pymobiledevice3.services.notification_proxy.NotificationProxyService ¶
Bases: LockdownService
Post and observe Darwin notifications on the device via the notification proxy lockdown service.
Allows sending notifications to the device, registering interest in notifications so the device
relays them back, and iterating over the relayed notifications. A secure or insecure variant of
the service is selected by the insecure flag, and the RSD/tunnel variant is chosen
automatically for RemoteServiceDiscoveryService providers. This is a lockdown service and is
used as an async context manager.
Source code in pymobiledevice3/services/notification_proxy.py
notify_post
async
¶
Post a notification on the device.
Sends a PostNotification command, causing the device to broadcast the named notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
notification name to post (e.g. a Darwin notification name). |
required |
Source code in pymobiledevice3/services/notification_proxy.py
notify_register_dispatch
async
¶
Register interest in a notification so the device relays it back.
Sends an ObserveNotification command; once registered, the device sends a message
whenever the named notification fires, which can be read via receive_notification.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
notification name to observe. |
required |
Source code in pymobiledevice3/services/notification_proxy.py
receive_notification
async
¶
Yield notifications relayed from the device for previously observed names.
Continuously reads from the service and yields each received message until the connection is closed.
Returns:
| Type | Description |
|---|---|
AsyncGenerator[dict, None]
|
an async generator of the received notification plists. |
Raises:
| Type | Description |
|---|---|
NotificationTimeoutError
|
if no notification arrives within the configured socket timeout. |
Source code in pymobiledevice3/services/notification_proxy.py
pymobiledevice3.services.power_assertion.PowerAssertionService ¶
Bases: LockdownService
Hold an IOKit power assertion on the device through the assertion agent lockdown service.
A power assertion prevents the device from sleeping (or otherwise alters its power behavior)
for as long as it is held. This is a lockdown service and is used as an async context manager;
the RSD/tunnel variant is selected automatically for non-LockdownClient providers.
Source code in pymobiledevice3/services/power_assertion.py
create_power_assertion
async
¶
Create a power assertion on the device, held for the duration of the with block.
Sends a create-assertion command to the agent, which calls IOPMAssertionCreateWithName
on the device. This is an async context manager: the assertion stays active while the block
is open.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
type_
|
str
|
IOKit assertion type (e.g. the assertion-type string passed to
|
required |
name
|
str
|
human-readable name identifying the assertion. |
required |
timeout
|
float
|
assertion timeout in seconds, after which the device may release it. |
required |
details
|
Optional[str]
|
optional descriptive detail string attached to the assertion. |
None
|
Source code in pymobiledevice3/services/power_assertion.py
pymobiledevice3.services.heartbeat.HeartbeatService ¶
Keep an active connection alive with the device's heartbeat lockdown service.
The device periodically sends Marco messages over com.apple.mobile.heartbeat and expects a
Polo reply; exchanging them prevents the connection from being torn down. The RSD/tunnel variant
of the service is selected automatically when the provider is not a plain LockdownClient.
Source code in pymobiledevice3/services/heartbeat.py
start
async
¶
Start the heartbeat exchange loop.
Opens the heartbeat service and, in a loop, receives each message from the device and replies
with Polo to keep the connection alive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval
|
Optional[float]
|
when set, stop the loop once roughly this many seconds have elapsed since it started; when None, the loop runs indefinitely. |
None
|
Source code in pymobiledevice3/services/heartbeat.py
pymobiledevice3.services.companion.CompanionProxyService ¶
Bases: LockdownService
Query and interact with companion devices (e.g. a paired Apple Watch) via the companion proxy lockdown service.
Provides access to the paired-device registry, live notifications of companion devices coming
and going, registry value lookups, and TCP port forwarding to a companion device. This is a
lockdown service and is used as an async context manager; the RSD/tunnel variant is selected
automatically for non-LockdownClient providers.
Source code in pymobiledevice3/services/companion.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 | |
list
async
¶
List the companion devices currently paired with the device.
Sends a GetDeviceRegistry command and returns the paired-device registry.
Returns:
| Type | Description |
|---|---|
|
the list of paired devices (the |
Source code in pymobiledevice3/services/companion.py
listen_for_devices
async
¶
Yield events as companion devices appear and disappear.
Sends StartListeningForDevices and then continuously yields each event message the
device emits.
Returns:
| Type | Description |
|---|---|
|
an async generator of device registry change events. |
Source code in pymobiledevice3/services/companion.py
get_value
async
¶
Read a single value from the registry of a specific companion device.
Sends a GetValueFromRegistry command for the given device and key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
udid
|
str
|
UDID of the companion device to query. |
required |
key
|
str
|
registry key whose value should be retrieved. |
required |
Returns:
| Type | Description |
|---|---|
|
the retrieved value dictionary. |
Raises:
| Type | Description |
|---|---|
PyMobileDevice3Exception
|
if the device returns an error instead of a value. |
Source code in pymobiledevice3/services/companion.py
start_forwarding_service_port
async
¶
start_forwarding_service_port(remote_port: int, service_name: Optional[str] = None, options: Optional[dict] = None)
Start forwarding a port on the companion device through the proxy.
Sends a StartForwardingServicePort command for the given remote port. The request
defaults the forwarded service to non-low-priority and does not prefer Wi-Fi; these and any
other fields may be overridden via options.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remote_port
|
int
|
port number on the companion device to forward. |
required |
service_name
|
Optional[str]
|
optional name of the forwarded service, sent as |
None
|
options
|
Optional[dict]
|
optional dictionary merged into the request to override default fields. |
None
|
Returns:
| Type | Description |
|---|---|
|
the local proxy port assigned for the forwarded connection
(the |
Source code in pymobiledevice3/services/companion.py
stop_forwarding_service_port
async
¶
Stop a port forward previously started with start_forwarding_service_port.
Sends a StopForwardingServicePort command for the given remote port.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remote_port
|
int
|
port number on the companion device whose forwarding should be stopped. |
required |
Returns:
| Type | Description |
|---|---|
|
the device's response to the stop command. |
Source code in pymobiledevice3/services/companion.py
pymobiledevice3.services.preboard.PreboardService ¶
Bases: LockdownService
Manage preboard stashbags on the device via the com.apple.preboardservice_v2 lockdown service.
A stashbag holds key material that allows the device to unlock data-protection classes during an
unattended reboot (e.g. before the user enters their passcode). This service creates and commits
such stashbags. This is a lockdown service and is used as an async context manager; the
RSD/tunnel variant is selected automatically for non-LockdownClient providers.
Source code in pymobiledevice3/services/preboard.py
create_stashbag
async
¶
Create a stashbag on the device.
Sends a CreateStashbag command with the given manifest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
the stashbag manifest describing the key material to stash. |
required |
Returns:
| Type | Description |
|---|---|
|
the device's response to the command. |
Source code in pymobiledevice3/services/preboard.py
commit
async
¶
Commit a previously created stashbag on the device.
Sends a CommitStashbag command with the given manifest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifest
|
the stashbag manifest to commit. |
required |
Returns:
| Type | Description |
|---|---|
|
the device's response to the command. |
Source code in pymobiledevice3/services/preboard.py
pymobiledevice3.services.restore_service.RestoreService ¶
Bases: RemoteService
Issue restore-time control commands to restoreserviced over RemoteXPC.
Wraps the com.apple.RestoreRemoteServices.restoreserviced remote service, exposing commands
used during the restore/recovery flow such as entering recovery, rebooting, and reading nonces
and preflight information. This is a remote service reached over RSD and is used as an async
context manager.
Source code in pymobiledevice3/services/restore_service.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
delay_recovery_image
async
¶
Request that the recovery image be delayed.
Sends the delayrecoveryimage command, which is only honored on devices of ProductType
0x1677b394 and otherwise fails.
Raises:
| Type | Description |
|---|---|
PyMobileDevice3Exception
|
if the device does not report success. |
Source code in pymobiledevice3/services/restore_service.py
enter_recovery
async
¶
Put the device into recovery mode.
Sends the recovery command.
Raises:
| Type | Description |
|---|---|
PyMobileDevice3Exception
|
if the device does not report success. |
Source code in pymobiledevice3/services/restore_service.py
reboot
async
¶
Reboot the device.
Sends the reboot command.
Raises:
| Type | Description |
|---|---|
PyMobileDevice3Exception
|
if the device does not report success. |
get_preflightinfo
async
¶
Retrieve restore preflight information from the device.
Sends the getpreflightinfo command.
Returns:
| Type | Description |
|---|---|
dict
|
the device's preflight info response. |
Source code in pymobiledevice3/services/restore_service.py
get_nonces
async
¶
Retrieve the device's restore nonces.
Sends the getnonces command.
Returns:
| Type | Description |
|---|---|
dict
|
the response containing the ApNonce and SEPNonce. |
Source code in pymobiledevice3/services/restore_service.py
get_app_parameters
async
¶
Retrieve restore app parameters from the device.
Sends the getappparameters command.
Returns:
| Type | Description |
|---|---|
dict
|
the device's app parameters response. |
Raises:
| Type | Description |
|---|---|
PyMobileDevice3Exception
|
if the device does not report success. |
Source code in pymobiledevice3/services/restore_service.py
restore_lang
async
¶
Set the restore language.
Sends the restorelang command with the given language as its argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
language
|
str
|
the language identifier to set for the restore. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
the device's response to the command. |
Source code in pymobiledevice3/services/restore_service.py
validate_command
async
¶
Send a command and assert that the device reports success.
Sends the given command and verifies the response result is "success".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
str
|
the restore command name to send. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
the device's response. |
Raises:
| Type | Description |
|---|---|
PyMobileDevice3Exception
|
if the response result is not |
Source code in pymobiledevice3/services/restore_service.py
pymobiledevice3.services.device_arbitration.DtDeviceArbitration ¶
Bases: LockdownService
Claim and release exclusive use of a device via the com.apple.dt.devicearbitration service.
Device arbitration lets a host check a device in (claiming it, optionally forcibly) so other hosts know it is in use, and check it back out when done. This is a developer lockdown service (it requires the DeveloperDiskImage to be mounted) and is used as an async context manager.
Source code in pymobiledevice3/services/device_arbitration.py
version
async
¶
Query the arbitration service version.
Sends the version command.
Returns:
| Type | Description |
|---|---|
dict
|
the device's version response. |
check_in
async
¶
Claim the device for the given host.
Sends a check-in command tagging the device with hostname. When force is True,
a force-check-in command is sent instead, taking the device even if another host holds it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
identifier of the host claiming the device. |
required |
force
|
bool
|
when True, forcibly claim the device even if it is already in use. |
False
|
Raises:
| Type | Description |
|---|---|
DeviceAlreadyInUseError
|
if the device is already checked in by another host
(and |
Source code in pymobiledevice3/services/device_arbitration.py
check_out
async
¶
Release a previously claimed device.
Sends the check-out command.
Raises:
| Type | Description |
|---|---|
ArbitrationError
|
if the device does not report success. |
Source code in pymobiledevice3/services/device_arbitration.py
pymobiledevice3.services.idam.IDAMService ¶
Bases: LockdownService
Query and set the device's IDAM configuration via the com.apple.idamd lockdown service.
Exposes reading the current IDAM configuration and toggling it. This is a lockdown service and
is used as an async context manager; the RSD/tunnel variant is selected automatically for
non-LockdownClient providers.
Source code in pymobiledevice3/services/idam.py
configuration_inquiry
async
¶
Read the device's current IDAM configuration.
Sends a Configuration Inquiry request.
Returns:
| Type | Description |
|---|---|
dict
|
the device's IDAM configuration response. |
Source code in pymobiledevice3/services/idam.py
set_idam_configuration
async
¶
Set the device's IDAM configuration.
Sends a Set IDAM Configuration request with the given value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
bool
|
the IDAM configuration flag to apply. |
required |