mypy-boto3-machinelearning
mypy-boto3-machinelearning provides type annotations for the `boto3` Machine Learning service, generated by `mypy-boto3-builder`. It enhances development experience by enabling static type checking with tools like MyPy and improving IDE autocomplete for AWS Boto3 clients, paginators, waiters, and response `TypedDict`s. The library is actively maintained with releases often mirroring `boto3` versions.
Warnings
- breaking Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0 and later, affecting all generated packages including `mypy-boto3-machinelearning`. Projects now require Python >= 3.9.
- breaking In `mypy-boto3-builder` version 8.9.0, there were changes to `TypeDef` naming conventions. Specifically, `TypeDef`s for packed method arguments use shorter names, and conflicting `Extra` postfixes were moved to the end. This can break explicit imports of `TypeDef`s.
- gotcha The overarching `mypy-boto3` project has been superseded by `types-boto3` and `boto3-stubs` for general `boto3` type annotations. While service-specific packages like `mypy-boto3-machinelearning` continue to be released under their current name, be aware of the shift in the main project's branding if you are looking for generic `boto3` stubs.
- gotcha The library migrated to PEP 561 compliance. This means type checkers should automatically discover the stubs. However, in some IDEs (e.g., VSCode), explicit type annotations for `boto3.client()` calls are still recommended to get full auto-complete and type hint benefits due to limitations in function overload support.
Install
-
pip install mypy-boto3-machinelearning boto3 -
pip install mypy
Imports
- MachineLearningClient
from mypy_boto3_machinelearning.client import MachineLearningClient
- DescribeMLModelsPaginator
from mypy_boto3_machinelearning.paginator import DescribeMLModelsPaginator
- MLModelAvailableWaiter
from mypy_boto3_machinelearning.waiter import MLModelAvailableWaiter
- CreateMLModelInputRequestTypeDef
from mypy_boto3_machinelearning.type_defs import CreateMLModelInputRequestTypeDef
Quickstart
import boto3
import os
from mypy_boto3_machinelearning.client import MachineLearningClient
def get_ml_client(region: str) -> MachineLearningClient:
"""Initializes and returns a type-hinted MachineLearning client."""
client: MachineLearningClient = boto3.client("machinelearning", region_name=region)
return client
def list_all_ml_models() -> None:
"""Lists all ML models using the type-hinted client."""
region = os.environ.get('AWS_REGION', 'us-east-1')
try:
ml_client = get_ml_client(region)
print(f"Listing ML models in {region}...")
response = ml_client.describe_ml_models()
for model in response.get('Results', []):
print(f" Model ID: {model.get('MLModelId')}, Name: {model.get('MLModelName')}")
print("Successfully listed ML models.")
except Exception as e:
print(f"Error listing ML models: {e}")
if __name__ == "__main__":
# Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
# Example: export AWS_REGION='us-east-1'
list_all_ml_models()