mypy-boto3-sagemaker-metrics type annotations

1.42.3 · active · verified Sat Apr 11

mypy-boto3-sagemaker-metrics provides PEP 561 compatible type annotations for the boto3 AWS SDK's SageMakerMetrics service. It enhances development with static type checking, improved IDE auto-completion, and early error detection for SageMakerMetrics client operations. The library is actively maintained, with versions typically aligned with boto3 releases and generated by mypy-boto3-builder.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the type-hinted SageMakerMetrics client to put batch metrics. It shows the correct way to instantiate a client with explicit type annotation and then call a service method, benefiting from IDE auto-completion and static type checks. Replace `my-trial-component-name` with an actual SageMaker Trial Component name for execution.

import boto3
from datetime import datetime
from mypy_boto3_sagemaker_metrics.client import SageMakerMetricsClient


def put_example_metrics(trial_component_name: str):
    client: SageMakerMetricsClient = boto3.client("sagemaker-metrics")

    response = client.batch_put_metrics(
        TrialComponentName=trial_component_name,
        MetricData=[
            {
                'MetricName': 'accuracy',
                'Timestamp': datetime.now(),
                'Step': 0,
                'Value': 0.95
            },
            {
                'MetricName': 'loss',
                'Timestamp': datetime.now(),
                'Step': 0,
                'Value': 0.05
            },
        ]
    )

    print(f"Successfully put metrics: {response}")

# Example usage (requires an existing SageMaker Trial Component)
# try:
#     put_example_metrics("my-trial-component-name")
# except Exception as e:
#     print(f"Error putting metrics: {e}")

# Note: Creating a Trial Component is outside the scope of this quickstart.
# You would typically get this name from a SageMaker training job or experiment.

view raw JSON →