Type Annotations for boto3 DirectoryServiceData

1.42.3 · active · verified Sat Apr 11

mypy-boto3-ds-data provides type annotations for the `boto3` DirectoryServiceData service, enabling robust static type checking with tools like Mypy. It is part of the `mypy-boto3` project, which generates comprehensive stubs for all AWS services based on their API definitions. The current version, 1.42.3, is designed to align with recent `boto3` releases and receives frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a type-hinted `DirectoryServiceDataClient` and use it to call a service method like `list_tags_for_resource`. It shows importing the client type and a request `TypeDef` for enhanced type checking. Remember to replace placeholder `ResourceId` with a valid one in your AWS account for actual execution.

import boto3
from mypy_boto3_ds_data.client import DirectoryServiceDataClient
from mypy_boto3_ds_data.type_defs import ListTagsForResourceRequestRequestTypeDef
import os

def get_directory_service_data_client() -> DirectoryServiceDataClient:
    """Initializes and returns a type-hinted DirectoryServiceData client."""
    # Actual credentials will come from environment variables or AWS config
    # os.environ.get('AWS_ACCESS_KEY_ID', ''), etc.
    return boto3.client("ds-data")

client: DirectoryServiceDataClient = get_directory_service_data_client()

# Example usage with type-checked parameters
# Replace 'd-xxxxxxxxxx' with an actual Directory ID in your AWS account
# or handle if the resource might not exist.
resource_id = os.environ.get('DS_DATA_RESOURCE_ID', 'd-xxxxxxxxxx') # Placeholder

try:
    params: ListTagsForResourceRequestRequestTypeDef = {
        "ResourceId": resource_id
    }
    response = client.list_tags_for_resource(**params)
    print("Tags for resource:")
    for tag in response.get('Tags', []):
        print(f"  {tag['Key']}: {tag['Value']}")
except client.exceptions.ResourceNotFoundException:
    print(f"Resource ID '{resource_id}' not found. Please provide a valid Directory ID.")
except Exception as e:
    print(f"An error occurred: {e}")

view raw JSON →