Type annotations for boto3 Customer Profiles
This library provides type annotations (stubs) for the `boto3` AWS SDK, specifically for the CustomerProfiles service. It enables static type checking tools like Mypy to validate `boto3` usage, preventing common runtime errors related to incorrect arguments or return types. The current version is 1.42.66, and releases are frequent, synchronized with `boto3` and `botocore` updates.
Warnings
- gotcha This package provides *only* type stubs. You must install `boto3` separately (e.g., `pip install boto3`) for your code to run at runtime. `mypy-boto3-customer-profiles` is only for static analysis.
- breaking Python 3.8 is no longer supported. This project now requires Python >=3.9 for all packages.
- breaking Packages migrated to PEP 561. This change improves how type checkers discover stubs but might require updates if you had custom Mypy configurations or explicit stub paths.
- gotcha Type definition names have changed in some cases (e.g., `CreateDistributionRequestRequestTypeDef` to `CreateDistributionRequestTypeDef`), and `Extra` postfixes were reordered. While `customer-profiles` might not be heavily impacted, be aware of potential breaking changes to TypeDef names.
- gotcha The `sms-voice` service was removed and replaced by `pinpoint-sms-voice` in version 8.11.0. While not directly affecting `customer-profiles`, this highlights a pattern where AWS service names/support can change, leading to breaking changes in generated stubs.
Install
-
pip install mypy-boto3-customer-profiles boto3 -
pip install mypy-boto3-customer-profiles
Imports
- CustomerProfilesClient
from mypy_boto3_customer_profiles.client import CustomerProfilesClient
- ListDomainsOutputTypeDef
from mypy_boto3_customer_profiles.type_defs import ListDomainsOutputTypeDef
Quickstart
import boto3
from mypy_boto3_customer_profiles.client import CustomerProfilesClient
from mypy_boto3_customer_profiles.type_defs import ListDomainsOutputTypeDef
# Initialize a boto3 client with type hints
client: CustomerProfilesClient = boto3.client("customer-profiles", region_name="us-east-1")
# Example operation: List Customer Profiles domains
try:
print("Listing Customer Profiles domains...")
# The response object will be typed as ListDomainsOutputTypeDef
response: ListDomainsOutputTypeDef = client.list_domains()
for domain in response.get("DomainList", []):
print(f" Domain ARN: {domain.get('DomainArn')}, Name: {domain.get('DomainName')}")
print("Successfully listed domains.")
except Exception as e:
print(f"Error listing domains: {e}")
# Example of creating a new profile (requires appropriate permissions)
# profile_data = {
# "DomainName": "your_domain_name",
# "FirstName": "John",
# "LastName": "Doe",
# "EmailAddress": "john.doe@example.com"
# }
# try:
# # You would use a specific type definition for the input here, e.g., CreateProfileRequestRequestTypeDef
# # client.create_profile(**profile_data)
# print("Profile creation commented out, uncomment to run.")
# except client.exceptions.ResourceNotFoundException:
# print("Domain not found. Ensure 'your_domain_name' exists.")
# except Exception as e:
# print(f"Error creating profile: {e}")