Skip to main content

start · quit · sessions

This tool on every surface: CLI · MCP · Python · JavaScript · Go · Java · .NET

Start or end the session on a device. These call app_session.

start​

def start(platform: str | None=None, device: str | None=None, app: str | None=None, driver: str | None=None, binary: str | None=None, call_timeout: float | None=None, session: str | None=None) -> 'Device'

Connect and open the session on the device.

platform: "android" or "ios"; "ios" picks wda, so the driver need not be named. device: serial or UDID, when more than one is running. app: a package name (Android) or bundle id (iOS) to launch once the session is up; start returns when it is in front. driver, binary, call_timeout, session: as for connect().

Nothing requires it -- every call opens a session on first use -- but it puts the slow first start (installing UiAutomator2, building WebDriverAgent on an iPhone) where it was asked for. End it with quit(), or use it in a with block, which quits on the way out:

with start(platform="android", app="com.android.settings") as device:
device.map()

quit​

def quit() -> None

End the session on the device and close the connection.

The teardown is the daemon's own: accessibility settings put back, a recording or route stopped, WebViews detached, the device-side server stopped, and the app start() launched, if any, stopped too. Quitting a session that is not open succeeds, and a second quit -- say, a with block ending after an explicit one -- does nothing. A script that exits without quit() or close() has the sessions it started ended for it: mobium sees the client go.

sessions​

def sessions() -> list[dict]

The sessions open on the daemon, each with device, platform and driver.

Examples​

Start a session and launch the app fresh​

device = mobium.start(app="com.android.settings")
print(device.session.platform, device.session.driver)

The same call from the command line, mobium session start --app com.android.settings, printed on an Android 15 emulator:

session already open on emulator-5554 (android, uiautomator2); com.android.settings was launched fresh and is in the foreground

End it, putting back what it changed​

device.quit()

The same call from the command line, mobium session end, printed on an Android 15 emulator:

session ended on emulator-5554; anything it changed for the session is put back; com.android.settings, which the session launched, was stopped