Type Annotations for boto3 WorkSpaces
mypy-boto3-workspaces provides type annotations for the AWS WorkSpaces service client in the boto3 library. It enables static type checking with tools like MyPy, improving code quality and catching potential errors at development time. This package is generated by mypy-boto3-builder and its versioning is tied to the boto3 release cycle.
Warnings
- breaking Python 3.8 is no longer supported. `mypy-boto3-builder` version 8.12.0 (which generated `mypy-boto3-workspaces` 1.42.66) removed support for Python 3.8 across all generated packages.
- breaking Migration to PEP 561 compliant packages. `mypy-boto3-builder` 8.12.0 changed how these stub packages are structured for PEP 561 compliance. While generally beneficial for automatic discovery by type checkers, custom MyPy configurations might require adjustments.
- gotcha These packages provide only type stubs. They do not contain the runtime logic for AWS interactions. You must have `boto3` installed separately to use the AWS SDK functionality at runtime.
- breaking TypedDict naming conventions changed in `mypy-boto3-builder` 8.9.0. This can lead to breaking changes for specific `TypedDict` names, for example, by removing redundant 'Request' suffixes (e.g., `FooRequestRequestTypeDef` might become `FooRequestTypeDef`).
Install
-
pip install mypy-boto3-workspaces
Imports
- WorkSpacesClient
from mypy_boto3_workspaces import WorkSpacesClient
- WorkSpacesServiceName
from mypy_boto3_workspaces import WorkSpacesServiceName
- DescribeWorkspacesRequestRequestTypeDef
from mypy_boto3_workspaces.type_defs import DescribeWorkspacesRequestRequestTypeDef
Quickstart
import boto3
from mypy_boto3_workspaces import WorkSpacesClient, WorkSpacesServiceName
from mypy_boto3_workspaces.type_defs import DescribeWorkspacesRequestRequestTypeDef
def list_all_workspaces(client: WorkSpacesClient):
"""Lists all WorkSpaces with type hints."""
print("Describing WorkSpaces...")
paginator = client.get_paginator("describe_workspaces")
all_workspaces = []
for page in paginator.paginate():
workspaces = page.get("Workspaces", [])
all_workspaces.extend(workspaces)
print(f"Found {len(all_workspaces)} WorkSpaces.")
for ws in all_workspaces[:3]: # Print first 3 for brevity
print(f"- {ws.get('WorkspaceId')} ({ws.get('State')})")
if __name__ == "__main__":
# Initialize a boto3 client for WorkSpaces
# The type hint here ensures MyPy checks usage against WorkSpacesClient stubs
workspaces_client: WorkSpacesClient = boto3.client(WorkSpacesServiceName.WORKSPACES)
list_all_workspaces(workspaces_client)