Type annotations for boto3 SageMaker
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
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generates these stubs), Python 3.8 support has been removed across all packages. Additionally, packages migrated to follow PEP 561 distribution standards.
- breaking Breaking changes in TypeDef naming conventions were introduced in `mypy-boto3-builder` 8.9.0. This includes shorter names for packed method arguments (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`) and moving `Extra` postfixes in conflicting TypeDefs (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`).
- gotcha Pylint may issue `undefined-variable` warnings when using `TYPE_CHECKING` blocks to conditionally import `mypy-boto3-*` types. This is a known issue with Pylint's handling of `TYPE_CHECKING`.
- gotcha PyCharm users might experience slow performance with Literal overloads in `boto3-stubs`. This is a known IDE issue (PY-40997).
- deprecated The `sms-voice` service was deprecated and removed from `mypy-boto3-builder` in version 8.11.0. Users of this service should migrate to `pinpoint-sms-voice`.
Install
-
pip install mypy-boto3-sagemaker -
pip install 'boto3-stubs[sagemaker]'
Imports
- SageMakerClient
from mypy_boto3_sagemaker.client import SageMakerClient
- SagemakerClient
from mypy_boto3_sagemaker import SagemakerClient
Quickstart
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}")