mypy-boto3-pca-connector-ad Type Annotations for AWS PcaConnectorAd Service
mypy-boto3-pca-connector-ad provides comprehensive type annotations for the `boto3` AWS PcaConnectorAd service (version 1.42.3), significantly enhancing IDE autocompletion and static analysis with tools like mypy and pyright. It is part of the `mypy-boto3-builder` ecosystem, which actively generates and updates stubs for various `boto3` services, ensuring up-to-date type information.
Warnings
- breaking As of `mypy-boto3-builder` version 8.12.0 (which generates `mypy-boto3-pca-connector-ad` 1.42.3), support for Python 3.8 has been removed for all generated packages.
- breaking Starting with `mypy-boto3-builder` 8.9.0, there were breaking changes to `TypeDef` naming conventions. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`, and `Extra` postfixes moved (`CreateDistributionExtraRequestTypeDef` to `CreateDistributionRequestExtraTypeDef`).
- gotcha `mypy-boto3-builder` 8.12.0 migrated all generated packages to PEP 561. While this improves standard compatibility, users with highly customized `mypy` configurations or build systems should be aware of potential impacts on how stubs are discovered.
- gotcha While `mypy-boto3` aims for implicit type discovery, some IDEs (especially VSCode without specific `mypy` integration) or specific configurations (like `boto3-stubs-lite`) might require explicit type annotations for `boto3.Session().client()` and similar calls to provide full autocompletion and static analysis.
- gotcha When using `typing.TYPE_CHECKING` guards to conditionally import type stubs (e.g., for Pylint compatibility), Pylint might report 'undefined variable' errors for the types within the runtime block.
Install
-
pip install mypy-boto3-pca-connector-ad -
pip install 'boto3-stubs[pca-connector-ad]'
Imports
- PcaConnectorAdClient
from mypy_boto3_pca_connector_ad.client import PcaConnectorAdClient
- ListConnectorsResponseTypeDef
from mypy_boto3_pca_connector_ad.type_defs import ListConnectorsResponseTypeDef
- PcaConnectorAdServiceName
from mypy_boto3_pca_connector_ad.literals import PcaConnectorAdServiceName
Quickstart
import os
from typing import TYPE_CHECKING
import boto3
from mypy_boto3_pca_connector_ad.client import PcaConnectorAdClient
from mypy_boto3_pca_connector_ad.type_defs import ListConnectorsResponseTypeDef
# The TYPE_CHECKING block is for type checkers and won't be executed at runtime.
# It's good practice for clarity and compatibility with various tooling setups.
if TYPE_CHECKING:
pass
def list_pca_connectors() -> None:
# Initialize a boto3 session. Credentials and region are typically loaded
# from environment variables, ~/.aws/credentials, or IAM roles.
# For a runnable example, we use dummy values if env vars are not set.
session = boto3.Session(
region_name=os.environ.get("AWS_REGION", "us-east-1"),
aws_access_key_id=os.environ.get("AWS_ACCESS_KEY_ID", "DUMMY_KEY"),
aws_secret_access_key=os.environ.get("AWS_SECRET_ACCESS_KEY", "DUMMY_SECRET"),
)
# Explicit type annotation for the client enhances autocompletion and static analysis
client: PcaConnectorAdClient = session.client("pca-connector-ad")
print("Attempting to list PCA Connectors...")
try:
# The response type is inferred by mypy-boto3-pca-connector-ad
response: ListConnectorsResponseTypeDef = client.list_connectors()
connectors = response.get('Connectors', [])
print(f"Found {len(connectors)} connectors.")
for connector in connectors:
print(f" - Connector ARN: {connector.get('Arn')}")
print(f" Type: {connector.get('Type')}, Status: {connector.get('Status')}")
except Exception as e:
print(f"Error listing connectors: {e}")
print("This is expected if AWS credentials or permissions are not configured correctly.")
if __name__ == "__main__":
list_pca_connectors()