Type annotations for boto3 MigrationHub
mypy-boto3-mgh provides type annotations for the boto3 MigrationHub service, enhancing static type checking for AWS SDK usage in Python. It is currently at version 1.42.3 and follows the release cadence of `mypy-boto3-builder`, which often aligns with `boto3` releases or significant internal changes, leading to frequent updates across many stub packages.
Warnings
- breaking Beginning with `mypy-boto3-builder` version 8.12.0 (and consequently all generated stub packages, including `mypy-boto3-mgh` 1.42.3), Python 3.8 is no longer supported. Projects targeting Python 3.8 will fail to type-check or even install these stubs.
- breaking The `mypy-boto3-builder` (from version 8.9.0) introduced breaking changes to TypeDef naming conventions. Argument TypeDefs now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes are moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`). This affects all generated service stubs.
- gotcha While `mypy-boto3` aims for automatic type discovery, some IDEs (like VSCode) may require explicit type annotations for `boto3.client()`, `session.client()`, `.get_waiter()`, and `.get_paginator()` calls to provide full auto-completion and type checking. PyCharm users are sometimes recommended to use `mypy-boto3-lite` to avoid performance issues with `Literal` overloads.
Install
-
pip install mypy-boto3-mgh -
pip install boto3 -
pip install mypy
Imports
- MigrationHubClient
from mypy_boto3_mgh.client import MigrationHubClient
- MigrationHubServiceName
from mypy_boto3_mgh.literals import MigrationHubServiceName
Quickstart
import os
import boto3
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_mgh.client import MigrationHubClient
def get_migrationhub_client() -> "MigrationHubClient":
"""
Retrieves a typed boto3 MigrationHub client.
"""
# boto3 automatically picks up credentials from environment variables,
# shared credential files, or IAM roles.
# For a quickstart, we assume credentials are set up.
session = boto3.Session(region_name=os.environ.get("AWS_REGION", "us-east-1"))
client: "MigrationHubClient" = session.client("migrationhub")
return client
if __name__ == "__main__":
# This example requires AWS credentials configured in your environment
# (e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION)
# or via ~/.aws/credentials.
# Try to get a client
mgh_client = get_migrationhub_client()
print(f"Successfully obtained MigrationHub client: {mgh_client}")
# You can now use mgh_client with full type hints, e.g.:
# response = mgh_client.list_application_states()
# print(response)