mypy-boto3-workdocs Type Annotations
mypy-boto3-workdocs provides type annotations for the boto3 WorkDocs service, ensuring static type checking compatibility with tools like mypy, VSCode, and PyCharm. It's automatically generated with mypy-boto3-builder, currently at version 1.42.3, and typically releases in sync with new boto3 and botocore versions.
Warnings
- breaking Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0 and later. Users on Python 3.8 will need to upgrade to Python 3.9 or newer.
- breaking TypeDef naming conventions changed in `mypy-boto3-builder` version 8.9.0. Some TypeDef names for packed method arguments became shorter (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`). This might break existing type hints that use the old names.
- gotcha When using PyCharm, performance issues with `Literal` overloads might lead to slow performance or high CPU usage. It is recommended to use `boto3-stubs-lite` (if available for your service) or disable PyCharm's type checker and rely on `mypy` or `pyright` instead.
- gotcha Pylint might report 'undefined variable' errors when using `TYPE_CHECKING` guards for `mypy-boto3` types. To fix this, set all types to `object` in the non-`TYPE_CHECKING` branch of your conditional imports.
- gotcha The `mypy-boto3` ecosystem migrated to PEP 561 compliant packages in version 8.12.0. While this is primarily an internal packaging change, it ensures better compatibility and discovery of type stubs by type checkers, but users should be aware of modern packaging practices.
Install
-
pip install mypy-boto3-workdocs boto3 mypy
Imports
- WorkDocsClient
from mypy_boto3_workdocs.client import WorkDocsClient
- DescribeUsersRequestRequestTypeDef
from mypy_boto3_workdocs.type_defs import DescribeUsersRequestRequestTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING
import os
if TYPE_CHECKING:
from mypy_boto3_workdocs.client import WorkDocsClient
from mypy_boto3_workdocs.type_defs import DescribeUsersResponseTypeDef
def get_workdocs_client() -> 'WorkDocsClient':
# In a real application, configure AWS credentials securely.
# For quickstart, using environment variables.
session = boto3.Session(
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', ''),
region_name=os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')
)
return session.client('workdocs')
if __name__ == '__main__':
client: WorkDocsClient = get_workdocs_client()
print(f"Client type: {type(client)}")
# Example: Describe users with explicit type hints
response: DescribeUsersResponseTypeDef = client.describe_users(
OrganizationId="your_organization_id" # Replace with actual Organization ID
)
print("Successfully described users.")
print(f"Users: {response.get('Users')}")
# Note: AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_DEFAULT_REGION
# and your_organization_id must be set for this to run successfully.