Type Annotations for boto3 ConnectCampaignService

1.42.3 · active · verified Sat Apr 11

mypy-boto3-connectcampaigns provides comprehensive type annotations for the AWS boto3 ConnectCampaignService. It's automatically generated with mypy-boto3-builder, ensuring up-to-date and accurate type hints for boto3 client calls, paginators, waiters, literals, and TypeDefs. This library helps developers leverage static analysis with tools like MyPy, Pyright, and IDEs for improved code quality and auto-completion. The current version is 1.42.3, following the boto3 release cycle.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use the `mypy-boto3-connectcampaigns` type annotations with a boto3 client. It shows explicit type hints for the client and a `TypeDef` for request parameters, which is particularly useful for complex AWS API calls. It includes a `TYPE_CHECKING` block to ensure the stub dependency is only active during static analysis, preventing runtime issues if the stub is not installed or to reduce production package size.

import boto3
import os
from typing import TYPE_CHECKING

# Conditional import for type checking only
if TYPE_CHECKING:
    from mypy_boto3_connectcampaigns import ConnectCampaignServiceClient
    from mypy_boto3_connectcampaigns.type_defs import CreateCampaignRequestTypeDef


def create_campaign_typed(
    client: 'ConnectCampaignServiceClient',
    instance_id: str,
    campaign_name: str
) -> dict:
    dialer_config: CreateCampaignRequestTypeDef['dialerConfig'] = {
        'progressiveDialerConfig': {
            'bandwidthAllocation': 1.0,
            'dialingCapacity': 100.0
        }
    }
    outbound_config: CreateCampaignRequestTypeDef['outboundCallConfig'] = {
        'connectContactFlowId': os.environ.get('CONNECT_CONTACT_FLOW_ID', 'dummy-flow-id'),
        'connectQueueId': os.environ.get('CONNECT_QUEUE_ID', 'dummy-queue-id'),
    }

    response = client.create_campaign(
        name=campaign_name,
        connectInstanceId=instance_id,
        dialerConfig=dialer_config,
        outboundCallConfig=outbound_config
    )
    print(f"Created campaign: {response.get('id')}")
    return response


# Example usage (runtime without type checking dependency)
if __name__ == "__main__":
    # In a real scenario, these would be actual AWS resource IDs
    connect_instance_id = os.environ.get(
        'CONNECT_INSTANCE_ID', 
        'arn:aws:connect:us-east-1:123456789012:instance/dummy-instance-id'
    )
    campaign_name = "MyTestCampaign"

    # Boto3 client without explicit type hint for runtime
    # Type checkers (like mypy) will infer ConnectCampaignServiceClient
    connect_campaigns_client = boto3.client('connectcampaigns')

    # Using the typed function
    print("Attempting to create a campaign...")
    try:
        # This call would typically fail without valid AWS credentials and resource IDs
        # For demonstration, we'll catch the expected client error
        result = create_campaign_typed(
            connect_campaigns_client, # type: ignore # Mypy might complain without explicit cast or if not in TYPE_CHECKING block
            connect_instance_id,
            campaign_name
        )
        print(f"Function returned (actual creation might fail without real AWS setup): {result}")
    except Exception as e:
        print(f"Caught expected error during campaign creation (requires valid AWS setup): {e}")
        print("Please ensure CONNECT_INSTANCE_ID, CONNECT_CONTACT_FLOW_ID, CONNECT_QUEUE_ID env vars are set for a successful run.")

view raw JSON →