mypy-boto3-notifications Type Annotations

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-notifications` to type-hint a `boto3` client for the AWS User Notifications service. It shows importing the client type and a request `TypeDef`, then using them to ensure type correctness when interacting with the service. This allows MyPy to catch potential errors during development.

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)

view raw JSON →