mypy-boto3-sagemaker-edge Type Annotations

1.42.3 · active · verified Sat Apr 11

mypy-boto3-sagemaker-edge provides type annotations for the boto3 SagemakerEdgeManager client, enhancing type checking capabilities for tools like MyPy, VSCode, and PyCharm. It is automatically generated by the `mypy-boto3-builder` and released frequently, typically in sync with `boto3` versions, to ensure up-to-date and accurate type hints. The current version is 1.42.3.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `boto3` SagemakerEdgeManager client with type annotations provided by `mypy-boto3-sagemaker-edge` and perform a basic operation like `send_heartbeat`. The `TYPE_CHECKING` block ensures that the stub types are only used during static analysis, preventing them from becoming a runtime dependency. Replace placeholder AWS credentials and region as needed.

import boto3
from typing import TYPE_CHECKING
import os

if TYPE_CHECKING:
    from mypy_boto3_sagemaker_edge.client import SagemakerEdgeManagerClient
    from mypy_boto3_sagemaker_edge.type_defs import SendHeartbeatRequestRequestTypeDef

# Configure AWS credentials and region (replace with your actual configuration)
# For quickstart, using environment variables or placeholder for simplicity
os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY')
os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_SECRET_KEY')
os.environ['AWS_REGION_NAME'] = os.environ.get('AWS_REGION_NAME', 'us-east-1')

def main():
    # Initialize the Sagemaker Edge Manager client with type hints
    client: SagemakerEdgeManagerClient = boto3.client("sagemaker-edge")

    # Example: Prepare a request for sending heartbeat with type definition
    heartbeat_request: SendHeartbeatRequestRequestTypeDef = {
        "AgentMetrics": [],  # List of AgentMetricTypeDef
        "Models": []        # List of ModelTypeDef
    }

    try:
        # Call an operation on the client
        response = client.send_heartbeat(**heartbeat_request)
        print("Heartbeat sent successfully.")
        print(f"Response Metadata: {response['ResponseMetadata']}")
    except client.exceptions.InternalServiceException as e:
        print(f"Error sending heartbeat: {e}")
    except Exception as e:
        print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    main()

view raw JSON →