mypy-boto3-notifications Type Annotations
Provides static type annotations for the `boto3` AWS User Notifications service client, enhancing code reliability through static type checking with tools like MyPy. It is version 1.42.3, generated by `mypy-boto3-builder`, and receives frequent updates in sync with new `boto3` releases and builder improvements.
Warnings
- breaking Python 3.8 support was removed from `mypy-boto3-builder` (which generates these stubs) in version 8.12.0. Users on Python 3.8 or older will need to upgrade their Python version to >=3.9 or use an older stub version.
- breaking Type definition (TypeDef) naming conventions changed in `mypy-boto3-builder` 8.9.0. This includes shorter names for packed method arguments (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`) and moving the `Extra` postfix. Code explicitly importing and using these `TypeDefs` may break.
- gotcha These packages (`mypy-boto3-notifications`) provide only type annotations. You must install `boto3` separately for the actual AWS SDK functionality at runtime. For type checking, `mypy` is also required as a development dependency.
- gotcha The `mypy-boto3` ecosystem migrated to PEP 561-compliant packages in `mypy-boto3-builder` 8.12.0. While this generally improves compatibility, some tools or custom configurations that relied on older stub discovery mechanisms might require adjustments.
- gotcha Occasionally, specific AWS services may be renamed or deprecated within the `boto3` ecosystem (e.g., `sms-voice` was replaced by `pinpoint-sms-voice`). While this specific stub is for `notifications`, keep an eye on upstream `boto3` changes, as they might eventually affect the service name or availability.
Install
-
pip install mypy-boto3-notifications boto3
Imports
- NotificationsClient
from mypy_boto3_notifications.client import NotificationsClient
- PublishRequestRequestTypeDef
from mypy_boto3_notifications.type_defs import PublishRequestRequestTypeDef
Quickstart
import boto3
from mypy_boto3_notifications.client import NotificationsClient
from mypy_boto3_notifications.type_defs import PublishRequestRequestTypeDef
# Ensure boto3 is installed: pip install boto3
def publish_notification(topic_arn: str, message: str) -> dict:
# Type-hint the boto3 client for AWS User Notifications
client: NotificationsClient = boto3.client("notifications")
request_params: PublishRequestRequestTypeDef = {
"Target": {"TargetArn": topic_arn}, # Example target
"Payload": {"Subject": "Alert", "Body": message}
}
try:
response = client.publish(request_params)
print(f"Notification published: {response.get('NotificationId')}")
return response
except Exception as e:
print(f"Error publishing notification: {e}")
raise
# Example usage (replace with actual ARN and message)
# if __name__ == '__main__':
# # NOTE: This example requires valid AWS credentials and a configured Notifications target
# # This service is for AWS User Notifications, which integrates with targets like AWS Chatbot or SNS.
# # For actual SNS topics, use boto3.client("sns").
# sample_topic_arn = "arn:aws:sns:REGION:ACCOUNT_ID:TOPIC_NAME" # This is just an example placeholder
# sample_message = "This is a test notification from mypy-boto3-notifications."
# # publish_notification(sample_topic_arn, sample_message)