Docs API Reference

API Reference

Complete documentation for every function in the MAS Python SDK.

Note: Device connection is handled automatically by MAS. Scripts do not need to explicitly connect or disconnect — the device is pre-configured when your script runs.

Types

Region

dataclass

A rectangular region on screen defined by corner coordinates.

from mas import Region
region = Region(x1=100, y1=200, x2=900, y2=260)
FieldTypeDescription
x1intLeft edge x-coordinate (pixels from left)
y1intTop edge y-coordinate (pixels from top)
x2intRight edge x-coordinate (pixels from left)
y2intBottom edge y-coordinate (pixels from top)

Screenshot

dataclass

Result of a screenshot capture operation.

FieldTypeDescription
base64strBase64-encoded PNG image data
widthintScreenshot width in pixels
heightintScreenshot height in pixels
timestampstrCapture timestamp in ISO 8601 format

ObjectMatch

dataclass

Result of a template matching operation.

FieldTypeDescription
xintCenter x coordinate
yintCenter y coordinate
centertuple[int, int]Property returning (x, y) tuple

TextRecognitionResult

dataclass

Result of OCR text recognition.

FieldTypeDescription
textstrExtracted text
confidencefloatRecognition confidence (0.0 to 1.0)
regionRegionRegion where text was found
languagestrLanguage code used for recognition

KeyCode

enum

Android hardware key codes.

BACK Back
HOME Home
MENU Menu
ENTER Enter
DELETE Delete
SPACE Space
POWER Power
VOLUME_UP Vol Up
VOLUME_DOWN Vol Down
DPAD_UP D-Pad Up
DPAD_DOWN D-Pad Down
DPAD_LEFT D-Pad Left

+ TAB, APP_SWITCH, CAMERA, MEDIA_PLAY, MEDIA_PAUSE, NUM_0–NUM_9, and more.

Device Control

mas.get_screen_size() ScreenSize

Get the current device screen dimensions.

size = mas.get_screen_size()
print(f"{size.width}x{size.height}")

mas.get_device_info() DeviceInfo

Get detailed information about the connected device.

info = mas.get_device_info()
print(f"{info.name} ({info.type})")

User Interaction

mas.click(x, y, delay_ms=100) None

Click at the specified coordinates.

ParamTypeDefaultDescription
xintrequiredHorizontal position (pixels from left)
yintrequiredVertical position (pixels from top)
delay_msint100Delay after click in milliseconds
mas.click(150, 300)
mas.click(150, 300, delay_ms=500)

mas.swipe(from_coords, to_coords, duration_ms=500) None

Perform a swipe gesture from one point to another.

ParamTypeDefaultDescription
from_coordstuple[int, int]requiredStarting (x, y) coordinates
to_coordstuple[int, int]requiredEnding (x, y) coordinates
duration_msint500Swipe duration in milliseconds
# Scroll down
mas.swipe((500, 1500), (500, 500), duration_ms=400)

mas.input_text(text, delay_ms=0) None

Type text into the currently focused input field.

ParamTypeDefaultDescription
textstrrequiredText to input
delay_msint0Delay after typing in milliseconds
mas.click(150, 200) # Focus input first
mas.input_text("user@example.com")

mas.key_press(key_code, modifiers=None, duration_ms=100) None

Press a hardware key or key combination.

ParamTypeDefaultDescription
key_codeKeyCoderequiredKey to press (from KeyCode enum)
modifierslist[Modifier] | NoneNoneModifier keys (Shift, Ctrl, Alt, Meta)
duration_msint100Duration to hold the key
mas.key_press(KeyCode.BACK)
mas.key_press(KeyCode.POWER, duration_ms=3000) # Long press

Computer Vision

mas.take_screenshot() Screenshot

Capture the current device screen as a base64-encoded image.

screenshot = mas.take_screenshot()
# Reuse for multiple searches
btn = mas.find_object(123, screenshot=screenshot)
icon = mas.find_object(456, screenshot=screenshot)

mas.find_object(image_id, ...) ObjectMatch | None

Find an image on screen using template matching.

ParamTypeDefaultDescription
image_idintrequiredID of the template image from your Image Library
thresholdfloat0.8Match confidence threshold (0.0 to 1.0)
screenshotScreenshot | NoneNoneOptional screenshot to reuse
continuous_modeboolFalseKeep searching until timeout or found
timeout_msint1000Timeout in milliseconds
match = mas.find_object(123)
if match: mas.click(*match.center)

mas.find_any_object(image_ids, ...) ObjectMatch | None

Find the first matching image from a list of templates.

ParamTypeDefaultDescription
image_idslist[int]requiredList of image IDs to search for
search_strategystr"first_match""first_match", "best_match", or "priority_order"
# Try multiple button variants
result = mas.find_any_object([123, 124, 125])

mas.read_text(region=None, language="eng", ...) TextRecognitionResult

Extract text from screen using OCR.

ParamTypeDefaultDescription
regionRegion | NoneNoneScreen region to read from (full screen if None)
languagestr"eng"Language code for OCR
text_filterstr"none""none", "integerOnly", "floatOnly", "alphanumeric", "pattern"
filter_patternstr | NoneNoneRegex pattern when text_filter is "pattern"
result = mas.read_text(text_filter="integerOnly")
score = int(result.text) if result.text else 0

mas.wait_for_object(image_id, timeout_ms=10000, threshold=0.8) ObjectMatch | None

Wait for an image to appear on screen (server-side polling).

home = mas.wait_for_object(200, timeout_ms=30000)
if home: mas.click(*home.center)

App Management

mas.open_app(package_name, timeout_ms=2000) None

Launch an Android application by package name.

mas.open_app("com.android.chrome")
mas.open_app("com.instagram.android", timeout_ms=5000)

mas.close_app(package_name) None

Force stop an Android application.

mas.close_app("com.instagram.android")

mas.get_current_app() str

Get the package name of the currently active application.

current = mas.get_current_app()
if "launcher" in current.lower():
mas.open_app("com.example.app")

Exceptions

The SDK provides a hierarchy of exceptions for error handling.

MASError (base)
|
RPCError
|-- ConnectionError
|-- ParseError (-32700)
|-- InvalidRequestError (-32600)
|-- MethodNotFoundError (-32601)
|-- InvalidParamsError (-32602)
|-- InternalError (-32603)
|-- DeviceNotConnectedError (-32001)
|-- DeviceNotFoundError (-32002)
|-- CommandFailedError (-32003)
|-- ImageNotFoundError (-32004)
|-- TimeoutError (-32005)

RPCError Attributes

codeintJSON-RPC error code
messagestrHuman-readable error message
dataAny | NoneOptional additional error data