Mypy Boto3 CloudDirectory - Type Annotations
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
- breaking Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0 and later. Projects using this library must use Python 3.9 or newer.
- breaking The `mypy-boto3-builder` migrated to PEP 561 compliant packages in version 8.12.0. This might affect how packages are discovered or handled by some tools, especially in complex project setups.
- breaking TypeDef naming conventions changed in `mypy-boto3-builder` version 8.9.0. Specifically, redundant `Request` postfixes were removed (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and `Extra` postfixes moved to the end of names. This could break existing explicit type annotations in your code.
- deprecated The `sms-voice` service was removed from `mypy-boto3-builder` in version 8.11.0. If your project uses type annotations for this service, you should migrate to `pinpoint-sms-voice`.
- gotcha PyCharm users might experience slow performance or high CPU usage due to `Literal` overloads when using the full `boto3-stubs` or standalone `mypy-boto3-*` packages. The `boto3-stubs-lite` versions are recommended as a workaround until the upstream PyCharm issue is resolved.
Install
-
pip install mypy-boto3-clouddirectory boto3
Imports
- CloudDirectoryClient
from mypy_boto3_clouddirectory.client import CloudDirectoryClient
- ListDirectoriesResponseTypeDef
from mypy_boto3_clouddirectory.type_defs import ListDirectoriesResponseTypeDef
Quickstart
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).")