mypy-boto3-controlcatalog
mypy-boto3-controlcatalog provides comprehensive type annotations for the AWS Control Catalog service within the `boto3` library. This allows static type checkers like MyPy and IDEs to offer accurate autocomplete, parameter suggestions, and error checking for your `boto3` client calls, improving code quality and developer productivity. It is generated by `mypy-boto3-builder` and its releases align with new `boto3` versions and `mypy-boto3-builder` updates.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0 (which generates `mypy-boto3-*` packages), support for Python 3.8 has been removed across all generated stub packages.
- breaking In `mypy-boto3-builder` version 8.9.0, there were breaking changes related to TypeDef naming conventions. Specifically, TypeDefs for packed method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`).
- gotcha These are type stubs for `boto3`. To benefit from type checking, you must also install a static type checker like `mypy` or `pyright` and configure your project to use it. The stubs alone do not alter `boto3`'s runtime behavior.
- gotcha For optimal performance and to avoid unnecessary runtime dependencies, it is recommended to install specific service stubs (e.g., `mypy-boto3-controlcatalog`) rather than the monolithic `boto3-stubs[all]` or `mypy-boto3` packages if you only use a few AWS services.
- gotcha When using `mypy-boto3` with PyCharm, older versions of PyCharm might exhibit slow performance or incorrect type inference, especially with `Literal` overloads.
Install
-
pip install mypy-boto3-controlcatalog
Imports
- ControlCatalogClient
from mypy_boto3_controlcatalog.client import ControlCatalogClient
- TYPE_CHECKING
from typing import TYPE_CHECKING
Quickstart
import os
from typing import TYPE_CHECKING
import boto3
if TYPE_CHECKING:
from mypy_boto3_controlcatalog.client import ControlCatalogClient
from mypy_boto3_controlcatalog.type_defs import ListDomainsOutputTypeDef
def get_controlcatalog_client() -> "ControlCatalogClient":
"""
Returns a typed ControlCatalog client.
"""
# boto3 automatically uses credentials from environment variables (e.g., AWS_ACCESS_KEY_ID)
# or ~/.aws/credentials.
# Replace "us-east-1" with your desired AWS region.
session = boto3.Session(region_name=os.environ.get("AWS_REGION", "us-east-1"))
client: "ControlCatalogClient" = session.client("controlcatalog")
return client
if __name__ == "__main__":
client = get_controlcatalog_client()
try:
# Example: List Control Catalog domains
# Replace with an actual Control Catalog operation for your use case.
response: "ListDomainsOutputTypeDef" = client.list_domains()
print(f"Successfully listed {len(response.get('Domains', []))} domains.")
for domain in response.get('Domains', []):
print(f"- Domain ARN: {domain.get('Arn')}, Name: {domain.get('Name')}")
except client.exceptions.ClientError as e:
print(f"Error listing domains: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")