mypy-boto3-sagemaker-metrics type annotations
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
- breaking As of `mypy-boto3-builder` version 8.12.0 (which generated `mypy-boto3-sagemaker-metrics` 1.42.3), Python 3.8 support has been explicitly removed. Projects requiring type stubs for this service must use Python 3.9 or newer.
- breaking In `mypy-boto3-builder` 8.9.0, there were breaking changes to TypeDef naming conventions. Specifically, suffixes like `RequestRequestTypeDef` were shortened to `RequestTypeDef`, and `Extra` postfixes were moved. While this specific package's service might not be directly affected, other `mypy-boto3` packages used in conjunction could break.
- gotcha This package provides *only* type annotations for `boto3`. It does not include the `boto3` library itself. You must install `boto3` separately for your code to run at runtime.
- gotcha The `mypy-boto3` libraries migrated to PEP 561 packages. While this generally improves compatibility with type checkers, older `mypy` configurations or non-standard `pip` usage might require explicit configuration or ensuring packages are installed in the environment where `mypy` runs.
Install
-
pip install mypy-boto3-sagemaker-metrics -
pip install boto3
Imports
- SageMakerMetricsClient
from mypy_boto3_sagemaker_metrics.client import SageMakerMetricsClient import boto3 client: SageMakerMetricsClient = boto3.client("sagemaker-metrics") - BatchPutMetricsResponseTypeDef
from mypy_boto3_sagemaker_metrics.type_defs import BatchPutMetricsResponseTypeDef
Quickstart
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.