Type Annotations for boto3 WorkSpaces

1.42.66 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to use the `mypy-boto3-workspaces` stubs with a `boto3` client. It shows type-hinting a boto3 client object with `WorkSpacesClient` to enable static analysis for WorkSpaces operations.

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)

view raw JSON →