Type annotations for boto3 Connect Campaign Service V2
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
- breaking Python 3.8 support has been removed. `mypy-boto3` packages (including this one) now require Python 3.9 or higher.
- breaking Migration to PEP 561 packages. This is an internal change primarily affecting how Python tools discover stubs.
- breaking TypeDef names for packed method arguments were shortened. E.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`.
- gotcha This package only provides type stubs. You must also install `boto3` (the actual AWS SDK) for your code to run.
- gotcha Version mismatch between `boto3` and `mypy-boto3-*` can lead to incorrect or missing type hints.
- gotcha Omitting `if TYPE_CHECKING:` for type imports will make `mypy-boto3-connectcampaignsv2` a runtime dependency, which is unnecessary overhead.
Install
-
pip install mypy-boto3-connectcampaignsv2 boto3 -
pip install mypy
Imports
- ConnectCampaignServiceV2Client
from mypy_boto3_connectcampaignsv2.client import ConnectCampaignServiceV2Client
- ListCampaignsResponseTypeDef
from mypy_boto3_connectcampaignsv2.type_defs import ListCampaignsResponseTypeDef
- TYPE_CHECKING
from typing import TYPE_CHECKING if TYPE_CHECKING: from mypy_boto3_connectcampaignsv2.client import ConnectCampaignServiceV2Client
Quickstart
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']