Type annotations for boto3 Connect Campaign Service V2

1.42.45 · active · verified Sat Apr 11

mypy-boto3-connectcampaignsv2 provides type annotations for the `boto3` AWS SDK's ConnectCampaignServiceV2. This library enhances developer experience by enabling static type checking with tools like MyPy and providing robust IDE autocompletion for the otherwise dynamically typed `boto3` library. It is currently at version 1.42.45 and is actively maintained with frequent updates tied to `boto3` and `mypy-boto3-builder` releases.

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize a type-hinted `boto3` client for ConnectCampaignServiceV2 and perform a simple operation (`list_campaigns`). The `if TYPE_CHECKING:` block ensures that the `mypy-boto3` stubs are only used for static analysis and not as a runtime dependency. Ensure AWS credentials are set in your environment for `boto3` to function.

from __future__ import annotations
import boto3
import os
from typing import TYPE_CHECKING

# Guard type-only imports with TYPE_CHECKING
if TYPE_CHECKING:
    from mypy_boto3_connectcampaignsv2.client import ConnectCampaignServiceV2Client
    from mypy_boto3_connectcampaignsv2.type_defs import ListCampaignsResponseTypeDef

def list_all_connect_campaigns() -> ListCampaignsResponseTypeDef:
    """Lists all Connect Campaigns using type-hinted boto3 client."""
    # boto3 client is dynamically typed by default
    # The type hint from mypy-boto3 provides static analysis capabilities
    client: ConnectCampaignServiceV2Client = boto3.client(
        "connectcampaignsv2",
        region_name=os.environ.get("AWS_REGION", "us-east-1"),
        aws_access_key_id=os.environ.get("AWS_ACCESS_KEY_ID", ""),
        aws_secret_access_key=os.environ.get("AWS_SECRET_ACCESS_KEY", "")
    )

    print("Fetching Connect Campaigns...")
    response: ListCampaignsResponseTypeDef = client.list_campaigns()
    
    for campaign in response.get("campaigns", []):
        print(f"  Campaign ID: {campaign.get('id')}, Name: {campaign.get('name')}")
    
    print(f"Total campaigns found: {len(response.get('campaigns', []))}")
    return response

if __name__ == "__main__":
    # This code will run even without mypy-boto3 installed, 
    # but mypy would check its types during static analysis.
    campaign_data = list_all_connect_campaigns()
    # You can access typed attributes here, e.g., campaign_data['campaigns']

view raw JSON →