mypy-boto3-datasync Type Stubs
mypy-boto3-datasync provides type annotations for `boto3`'s DataSync service client, enhancing static analysis with tools like MyPy. It ensures type safety for `boto3` calls, improving developer experience and catching potential errors pre-runtime. The library closely tracks `boto3` and AWS API releases, leading to frequent updates, currently at version 1.42.85.
Warnings
- breaking Python 3.8 support has been removed. All `mypy-boto3` packages now require Python 3.9 or newer.
- breaking Some generated `TypeDef` names were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`) and conflicting `TypeDef` postfixes were reordered. This can cause `mypy` errors if you explicitly imported these types.
- gotcha All `mypy-boto3` packages, including `mypy-boto3-datasync`, migrated to PEP 561-compliant packages. While this improves standard stub discovery, older `mypy` configurations or custom stub paths might need adjustment to correctly locate the stubs.
- gotcha These packages provide type hints for static analysis only. They do not modify `boto3`'s runtime behavior or add any runtime type checking. Any runtime errors will still occur as per `boto3`'s behavior.
Install
-
pip install mypy-boto3-datasync -
pip install boto3-stubs[datasync]
Imports
- DataSyncClient
from mypy_boto3_datasync.client import DataSyncClient
- ListTasksResponseTypeDef
from mypy_boto3_datasync.type_defs import ListTasksResponseTypeDef
- ListTasksPaginator
from mypy_boto3_datasync.paginator import ListTasksPaginator
Quickstart
import boto3
from mypy_boto3_datasync.client import DataSyncClient
from mypy_boto3_datasync.type_defs import ListTasksResponseTypeDef
# Initialize a boto3 client with type hinting
# (Mypy may warn without # type: ignore, but it's correct for runtime use)
client: DataSyncClient = boto3.client("datasync", region_name="us-east-1")
try:
# Use the client with type-safe operations
response: ListTasksResponseTypeDef = client.list_tasks(MaxResults=5)
print(f"Found {len(response.get('TaskList', []))} DataSync tasks.")
for task in response.get('TaskList', []):
print(f" Task ARN: {task.get('TaskArn')}, Name: {task.get('Name')}")
except Exception as e:
print(f"An error occurred: {e}")
print("Ensure AWS credentials are configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION environment variables or ~/.aws/credentials).")