Type annotations for boto3 SageMaker

1.42.88 · active · verified Fri Apr 10

mypy-boto3-sagemaker provides type annotations for the boto3 SageMaker service. These stubs are generated with mypy-boto3-builder to offer type checking and IDE auto-completion for your boto3 SageMaker clients. The library is actively maintained with frequent releases, currently at version 1.42.88, ensuring compatibility with the latest boto3 versions and Python type-hinting standards.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a type-hinted SageMaker client using `boto3` and `mypy-boto3-sagemaker`. The `SageMakerClient` type provides comprehensive type checking and auto-completion for all available SageMaker API operations and their parameters.

import boto3
from boto3.session import Session
from mypy_boto3_sagemaker.client import SagemakerClient

def get_sagemaker_client() -> SagemakerClient:
    # boto3 automatically picks up credentials from environment variables or AWS config.
    # For local testing without actual AWS calls, ensure 'boto3' is configured.
    session = Session()
    client: SagemakerClient = session.client("sagemaker")
    return client

# Example usage (will only run if AWS credentials are set up)
if __name__ == "__main__":
    try:
        sagemaker_client = get_sagemaker_client()
        # Access type-hinted methods, e.g., sagemaker_client.list_training_jobs()
        print(f"Successfully created SageMaker client: {sagemaker_client.meta.region_name}")
        # Uncomment below to make an actual API call (requires permissions)
        # response = sagemaker_client.list_training_jobs(MaxResults=1)
        # print(f"Training jobs: {response.get('TrainingJobSummaries')}")
    except Exception as e:
        print(f"Error creating SageMaker client or making call: {e}")

view raw JSON →