mypy-boto3-globalaccelerator type stubs
mypy-boto3-globalaccelerator provides type annotations for the boto3 GlobalAccelerator service. It helps developers leverage static type checking with Mypy for AWS Global Accelerator clients, improving code quality and catching potential errors at development time. The current version is 1.42.3, and new versions are regularly released in sync with boto3 and botocore updates.
Warnings
- breaking Python 3.8 support was removed in `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 must upgrade to Python 3.9 or newer to continue receiving updates for `mypy-boto3-*` packages.
- breaking All `mypy-boto3-*` packages migrated to PEP 561-compliant distribution in version 8.12.0. This change primarily affects how type checkers locate stubs, potentially requiring `mypy` or other tools to be updated to a version that properly handles PEP 561 packages.
- gotcha The `mypy-boto3-globalaccelerator` package provides type stubs for `boto3`, but does *not* install `boto3` itself. You must explicitly install `boto3` alongside the stubs package. Using `pip install mypy-boto3-globalaccelerator[globalaccelerator]` *will* install boto3, but this is an 'extra' and less explicit than installing `boto3` separately.
- gotcha For optimal type checking accuracy, the version of `mypy-boto3-globalaccelerator` should ideally match or closely align with your installed `boto3` version. Significant version discrepancies can lead to inaccurate type hints for new or changed service features.
- breaking In `mypy-boto3-builder` version 8.9.0, type definition naming conventions changed to use shorter names where possible (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). This might break code explicitly importing the old, longer type definition names.
Install
-
pip install mypy-boto3-globalaccelerator boto3 -
pip install mypy-boto3-globalaccelerator[globalaccelerator]
Imports
- GlobalAcceleratorClient
from mypy_boto3_globalaccelerator.client import GlobalAcceleratorClient
- CreateAcceleratorRequestTypeDef
from mypy_boto3_globalaccelerator.type_defs import CreateAcceleratorRequestTypeDef
Quickstart
import boto3
from mypy_boto3_globalaccelerator.client import GlobalAcceleratorClient
from mypy_boto3_globalaccelerator.type_defs import CreateAcceleratorRequestTypeDef
import os
def create_example_accelerator(name: str) -> str:
"""Creates an AWS Global Accelerator accelerator."""
# Ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
# The following line uses os.environ.get for illustration, boto3 handles credential lookup implicitly.
# AWS_ACCESS_KEY_ID = os.environ.get('AWS_ACCESS_KEY_ID', '')
# AWS_SECRET_ACCESS_KEY = os.environ.get('AWS_SECRET_ACCESS_KEY', '')
client: GlobalAcceleratorClient = boto3.client("globalaccelerator", region_name="us-west-2")
request_payload: CreateAcceleratorRequestTypeDef = {
"Name": name,
"IpAddressType": "IPV4",
"Enabled": True,
"Tags": [
{"Key": "Project", "Value": "ChecklistDay"},
{"Key": "Environment", "Value": "Dev"}
],
}
try:
response = client.create_accelerator(**request_payload)
accelerator_arn = response["AcceleratorArn"]
print(f"Successfully created accelerator: {accelerator_arn}")
return accelerator_arn
except client.exceptions.AcceleratorLimitExceededException as e:
print(f"Error: Accelerator limit exceeded. {e}")
return ""
except Exception as e:
print(f"An unexpected error occurred: {e}")
return ""
# Example usage (requires AWS credentials and appropriate permissions)
if __name__ == "__main__":
# For a real run, ensure your AWS environment is configured.
# For testing, you might mock boto3 or ensure you have a sandbox AWS account.
# Skipping actual execution for quickstart to avoid live resource creation.
# accelerator_arn = create_example_accelerator("MyTestGlobalAccelerator")
# if accelerator_arn:
# print(f"Accelerator created with ARN: {accelerator_arn}")
print("Quickstart example demonstrates type hinting. To run, uncomment the example usage and configure AWS credentials.")