Mypy Boto3 CloudDirectory - Type Annotations

1.42.3 · active · verified Sat Apr 11

mypy-boto3-clouddirectory provides type annotations for the AWS boto3 CloudDirectory service. It ensures static type checking with tools like mypy, enhancing code quality and developer experience for Python applications interacting with AWS CloudDirectory. The project's builder (`mypy-boto3-builder`) releases frequently, typically in sync with new boto3/botocore versions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to instantiate a boto3 CloudDirectory client with explicit type annotations using `mypy-boto3-clouddirectory`. It then calls `list_directories` and accesses the type-hinted response data, showing how the stub types improve code completion and static analysis.

import boto3
from mypy_boto3_clouddirectory.client import CloudDirectoryClient
from mypy_boto3_clouddirectory.type_defs import ListDirectoriesResponseTypeDef


def list_clouddirectory_stuff() -> ListDirectoriesResponseTypeDef:
    # Initialize a CloudDirectory client with type hints
    client: CloudDirectoryClient = boto3.client("clouddirectory")

    # Call an API operation; mypy will check arguments and return types
    response: ListDirectoriesResponseTypeDef = client.list_directories(
        MaxResults=5
    )
    
    print(f"Found {len(response.get('Directories', []))} directories.")
    # Example of accessing type-hinted data
    for directory in response.get('Directories', []):
        print(f"  - Directory ARN: {directory['DirectoryArn']}")
    return response

if __name__ == "__main__":
    # This code requires AWS credentials configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY env vars)
    # or a configured AWS CLI profile.
    # If no credentials are found, boto3 will raise a ClientError.
    try:
        list_clouddirectory_stuff()
    except Exception as e:
        print(f"An error occurred: {e}")
        print("Please ensure AWS credentials are configured (e.g., ~/.aws/credentials or environment variables).")

view raw JSON →