mypy-boto3-migrationhubstrategy: Type Annotations for AWS Migration Hub Strategy Recommendations
mypy-boto3-migrationhubstrategy provides type annotations for the `boto3` AWS SDK's Migration Hub Strategy Recommendations service. It offers static type checking and improved IDE autocompletion for `boto3` users, ensuring code correctness and developer efficiency. The library is currently at version 1.42.3 and follows a frequent release cadence, often aligning with `boto3` updates and new AWS service features. It is generated by `mypy-boto3-builder`.
Warnings
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 or older must upgrade their Python environment to 3.9 or newer to continue receiving updates for `mypy-boto3-*` packages, including `mypy-boto3-migrationhubstrategy`.
- gotcha When using standalone `mypy-boto3-*` packages, explicit type annotations are recommended for `boto3.client` or `session.client` calls (e.g., `client: MigrationHubStrategyRecommendationsClient = boto3.client(...)`). While type checkers might infer some types, explicit annotations ensure full autocompletion and static analysis benefits, especially when not using the larger `boto3-stubs` or `boto3-stubs-lite` packages.
- breaking `mypy-boto3-builder` version 8.9.0 introduced breaking changes to `TypeDef` naming conventions (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). If your code directly references these generated type definitions from older stub versions, it may break upon upgrade.
- gotcha As of `mypy-boto3-builder` 8.12.0, all generated packages have migrated to PEP 561, meaning stub files are now correctly located by type checkers without special configuration. If you previously relied on `MYPYPATH` to point to manually managed stub directories, this configuration might no longer be necessary or could behave unexpectedly.
- gotcha PyCharm users may experience performance issues or high CPU usage due to how PyCharm handles `Literal` overloads in type annotations. The `mypy-boto3` project itself recommends using `boto3-stubs-lite` (or the equivalent service-specific lite package, if available) as a workaround until this PyCharm issue (PY-40997) is resolved.
Install
-
pip install boto3 mypy-boto3-migrationhubstrategy
Imports
- MigrationHubStrategyRecommendationsClient
from mypy_boto3_migrationhubstrategy.client import MigrationHubStrategyRecommendationsClient
- ListApplicationComponentsResponseTypeDef
from mypy_boto3_migrationhubstrategy.type_defs import ListApplicationComponentsResponseTypeDef
- boto3.client
import boto3 from mypy_boto3_migrationhubstrategy.client import MigrationHubStrategyRecommendationsClient client: MigrationHubStrategyRecommendationsClient = boto3.client("migrationhubstrategy")
Quickstart
import boto3
import os
from mypy_boto3_migrationhubstrategy.client import MigrationHubStrategyRecommendationsClient
from mypy_boto3_migrationhubstrategy.type_defs import ListApplicationComponentsResponseTypeDef
def get_application_components() -> ListApplicationComponentsResponseTypeDef:
# Ensure AWS credentials are configured (e.g., via environment variables, ~/.aws/credentials)
# For this example, we assume valid credentials are set up in the environment.
# client: MigrationHubStrategyRecommendationsClient = boto3.client(
# "migrationhubstrategy",
# region_name=os.environ.get("AWS_REGION", "us-east-1")
# )
# The above is correct, but for a runnable quickstart focusing on *typing*,
# a minimal client creation is better without requiring full AWS setup for execution.
# In a real application, you'd configure region, credentials, etc. appropriately.
# Explicitly type the client for static analysis benefits
client: MigrationHubStrategyRecommendationsClient = boto3.client("migrationhubstrategy")
# Example API call with type-hinted response
response: ListApplicationComponentsResponseTypeDef = client.list_application_components()
print(f"Found {len(response.get('applicationComponentInfos', []))} application components.")
for component in response.get('applicationComponentInfos', []):
print(f"- {component.get('applicationComponentId')}: {component.get('applicationComponentName')}")
return response
if __name__ == "__main__":
# This part requires actual AWS credentials for a successful run.
# You might need to set AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and AWS_REGION
# in your environment for this to execute without credential errors.
try:
get_application_components()
except Exception as e:
print(f"An error occurred: {e}. Please ensure AWS credentials are configured.")