Type Annotations for boto3 DataZone
mypy-boto3-datazone provides type annotations for the boto3 DataZone service, enabling static type checking with tools like mypy, pyright, and enhanced IDE autocomplete. It is part of the `boto3-stubs` ecosystem, generated by `mypy-boto3-builder`. The current version is 1.42.85, released in sync with boto3 versions, ensuring compatibility and a frequent update cadence.
Warnings
- breaking Python 3.8 support was removed in `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 or older will need to upgrade their Python version to `>=3.9` to use recent versions of `mypy-boto3-datazone`.
- breaking Breaking changes in `mypy-boto3-builder` version 8.9.0 introduced shorter names for TypeDefs used in packed method arguments (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). Conflicting `Extra` postfixes in TypeDef names were also moved to the end.
- gotcha The standalone `mypy-boto3` package is considered legacy. While `mypy-boto3-datazone` is a valid and current service-specific stub, it is recommended to install service stubs using the `boto3-stubs` meta-package (e.g., `pip install 'boto3-stubs[datazone]'`) for better maintainability and to avoid confusion with the older `mypy-boto3` meta-package.
- gotcha Some IDEs (like older PyCharm versions) or linters might require explicit type annotations for `boto3.client` calls to ensure full autocomplete and type checking, due to limitations with function overloads.
Install
-
pip install mypy-boto3-datazone -
pip install 'boto3-stubs[datazone]'
Imports
- DataZoneClient
from mypy_boto3_datazone.client import DataZoneClient
- ListDomainsOutputTypeDef
from mypy_boto3_datazone.type_defs import ListDomainsOutputTypeDef
- ListDomainsPaginator
from mypy_boto3_datazone.paginator import ListDomainsPaginator
Quickstart
import boto3
from mypy_boto3_datazone.client import DataZoneClient
from mypy_boto3_datazone.type_defs import ListDomainsOutputTypeDef
from typing import TYPE_CHECKING, cast
if TYPE_CHECKING:
client: DataZoneClient = boto3.client("datazone")
else:
client = boto3.client("datazone")
def list_datazone_domains() -> ListDomainsOutputTypeDef:
"""Lists DataZone domains with type hints."""
# Example: List domains
response = client.list_domains()
print(f"Found {len(response.get('items', []))} DataZone domains.")
return cast(ListDomainsOutputTypeDef, response)
if __name__ == "__main__":
# Ensure boto3 is configured (e.g., AWS_REGION, AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
# For demonstration, we'll assume default config or environment variables.
try:
domains = list_datazone_domains()
for domain in domains.get('items', []):
print(f"- Domain ID: {domain.get('id')}, Name: {domain.get('name')}")
except Exception as e:
print(f"Error listing domains: {e}")
# In a real application, you'd handle specific boto3 exceptions.