Type Annotations for boto3 ConnectCampaignService
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
- breaking Python 3.8 support has been removed since `mypy-boto3-builder` version 8.12.0. Users must upgrade to Python 3.9 or newer.
- breaking TypeDef naming conventions changed in `mypy-boto3-builder` version 8.9.0. Packed method argument TypeDefs use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting 'Extra' postfixes moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`).
- deprecated The `sms-voice` service was deprecated and removed from `mypy-boto3-builder` in version 8.11.0. Users of `sms-voice` stubs should migrate to `pinpoint-sms-voice`.
- gotcha While MyPy and PyCharm often infer types automatically, VSCode and some other IDEs might require explicit type annotations for `boto3.client`, `boto3.session.client`, `client.get_waiter`, and `client.get_paginator` calls for full auto-completion and type checking.
- gotcha For conditional type checking to avoid runtime dependencies on stubs (e.g., in production builds) or to address `pylint` warnings about undefined variables, use `typing.TYPE_CHECKING` with fallback to `object`.
Install
-
pip install mypy-boto3-connectcampaigns boto3 -
pip install 'boto3-stubs[connectcampaigns]' boto3
Imports
- ConnectCampaignServiceClient
from mypy_boto3_connectcampaigns import ConnectCampaignServiceClient
- ListCampaignsPaginator
from mypy_boto3_connectcampaigns.paginator import ListCampaignsPaginator
- CampaignStateType
from mypy_boto3_connectcampaigns.literals import CampaignStateType
- CreateCampaignRequestTypeDef
from mypy_boto3_connectcampaigns.type_defs import CreateCampaignRequestTypeDef
Quickstart
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.")