mypy-boto3-devicefarm

1.42.3 · active · verified Sat Apr 11

mypy-boto3-devicefarm provides comprehensive type annotations for the boto3 DeviceFarm service, enabling static type checking with tools like mypy. These type stubs enhance IDE autocompletion, improve code readability, and help catch potential runtime errors before deployment. It is currently at version 1.42.3, with releases closely mirroring `boto3` updates via the `mypy-boto3-builder`.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to obtain a type-hinted `boto3` DeviceFarm client and use it to call `list_devices`. It includes conditional type imports (`if TYPE_CHECKING`) for clean runtime behavior and shows how to type-hint both the client object and API call responses. Remember to configure your AWS credentials and region, as Device Farm is a region-specific service.

import os
import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_devicefarm.client import DeviceFarmClient
    from mypy_boto3_devicefarm.type_defs import ListDevicesResponseTypeDef

def get_devicefarm_client() -> 'DeviceFarmClient':
    """Returns a type-hinted boto3 DeviceFarm client."""
    # Ensure AWS credentials are available via environment variables or other boto3 config
    # e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION
    session = boto3.Session(
        aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
        aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET'),
        region_name=os.environ.get('AWS_REGION', 'us-west-2') # Device Farm is region-specific
    )
    client: DeviceFarmClient = session.client('devicefarm')
    return client

def list_devicefarm_devices():
    """Lists available Device Farm devices with type hints."""
    client = get_devicefarm_client()
    
    print("Attempting to list Device Farm devices...")
    try:
        response: ListDevicesResponseTypeDef = client.list_devices(filters=[{'attribute': 'PLATFORM', 'operator': 'EQUALS', 'values': ['ANDROID']}])
        devices = response.get('devices', [])
        if devices:
            print(f"Found {len(devices)} Android devices:")
            for device in devices:
                print(f"  - {device.get('name')} (ARN: {device.get('arn')})")
        else:
            print("No Android devices found.")
    except client.exceptions.ServiceException as e:
        print(f"AWS Service Error: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

if __name__ == '__main__':
    list_devicefarm_devices()

view raw JSON →