Type annotations for boto3 MigrationHub

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to obtain a type-hinted MigrationHub client using `boto3` and `mypy-boto3-mgh`. The `TYPE_CHECKING` block is a common pattern to avoid importing stubs in production environments.

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)

view raw JSON →