mypy-boto3-pinpoint-sms-voice
This library provides essential type annotations for the `boto3` Pinpoint SMS Voice service, generated by `mypy-boto3-builder`. It enables static type checking with tools like Mypy, enhancing code quality and developer experience for AWS interactions. The current version is 1.42.3, and releases are frequent, typically in sync with `boto3` and `botocore` updates.
Warnings
- breaking The AWS service client name for Pinpoint SMS Voice was changed from `sms-voice` to `pinpoint-sms-voice` in `mypy-boto3-builder` version 8.11.0. Using the old name with newer `boto3` or `mypy-boto3` stubs will result in runtime errors (e.g., `ClientError` or `KeyError`).
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0. Consequently, `mypy-boto3-pinpoint-sms-voice` versions built with 8.12.0 or later (e.g., 1.42.x) require Python 3.9 or higher.
- gotcha While `mypy-boto3` automatically provides types for `boto3.client(...)` calls, explicit imports for `TypeDef` classes (e.g., `SendMessagesRequestRequestTypeDef`) must be guarded by `if TYPE_CHECKING:` to prevent potential runtime import errors if `mypy-boto3` is not installed or when running a compiled version.
- gotcha These packages provide static type stubs for `boto3`; they do not alter `boto3`'s runtime behavior. They are for compile-time type checking only. Actual AWS API calls still require `boto3` to be installed and properly configured with valid AWS credentials.
Install
-
pip install mypy-boto3-pinpoint-sms-voice boto3
Imports
- PinpointSMSVoiceClient
from typing import TYPE_CHECKING if TYPE_CHECKING: from mypy_boto3_pinpoint_sms_voice import PinpointSMSVoiceClient - SendMessagesRequestRequestTypeDef
from typing import TYPE_CHECKING if TYPE_CHECKING: from mypy_boto3_pinpoint_sms_voice.type_defs import SendMessagesRequestRequestTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING, cast
import os
# This package provides type stubs for boto3.client("pinpoint-sms-voice").
# Install `mypy-boto3-pinpoint-sms-voice` and `boto3` for type checking.
# --- Runtime code (runs without stubs, but benefits from them during development) ---
print("--- Runtime code ---")
# Ensure AWS credentials are configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY env vars)
# or ~/.aws/credentials.
# Example of creating a boto3 client at runtime
pinpoint_client = boto3.client(
"pinpoint-sms-voice",
region_name=os.environ.get('AWS_REGION', 'us-east-1')
)
print(f"Created boto3 client for {pinpoint_client.meta.service_model.service_name}")
# --- Type-checking specific code (only for static analysis tools like mypy) ---
if TYPE_CHECKING:
from mypy_boto3_pinpoint_sms_voice import PinpointSMSVoiceClient
from mypy_boto3_pinpoint_sms_voice.type_defs import SendMessagesRequestRequestTypeDef
# Mypy will understand that pinpoint_client is a PinpointSMSVoiceClient
# after the stubs are installed. An explicit cast is often not needed,
# but can be used for stricter checking or clarity.
typed_client: PinpointSMSVoiceClient = cast(PinpointSMSVoiceClient, pinpoint_client)
# Example of using a type definition for a request payload. Mypy validates its structure.
send_messages_request: SendMessagesRequestRequestTypeDef = {
"ApplicationId": "dummy-app-id", # Replace with your actual Pinpoint Application ID
"MessageRequest": {
"Addresses": {"+1234567890": {"ChannelType": "SMS"}}, # Replace with real phone numbers
"Message": {"Body": "Hello from checklist.day!"},
},
}
print("\n--- Type-checking example (mypy validates this structure) ---")
print(f"Request structure type: {type(send_messages_request)}")
# In a type-checked environment, you'd get auto-completion and validation for:
# typed_client.send_messages(**send_messages_request)
else:
print("\n--- To enable full type-checking, run `mypy your_script.py` after installation ---")
print("\nQuickstart complete. Ensure AWS credentials are configured for actual API calls.")