mypy-boto3-greengrassv2 Type Annotations
Type annotations for the boto3 GreengrassV2 service (version 1.42.3), generated with `mypy-boto3-builder`. This library provides static type checking for boto3 interactions, enhancing code readability, catching errors early, and improving IDE support. Its releases typically align with boto3 updates and the `mypy-boto3-builder`'s development cycle.
Warnings
- breaking `mypy-boto3-builder` (which generates this package) removed support for Python 3.8 starting from version 8.12.0. This means `mypy-boto3-greengrassv2` versions generated by `mypy-boto3-builder >= 8.12.0` require Python 3.9 or newer. Projects on Python 3.8 must pin an older version of `mypy-boto3-greengrassv2` or upgrade their Python interpreter.
- breaking Starting with `mypy-boto3-builder 8.9.0`, there were breaking changes to TypeDef naming conventions, such as `CreateDistributionRequestRequestTypeDef` becoming `CreateDistributionRequestTypeDef` and conflicting `Extra` postfixes being moved (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`). Code that explicitly imports and uses these TypeDefs may need adjustment.
- gotcha Forgetting to wrap `mypy-boto3-*` imports within an `if TYPE_CHECKING:` block can inadvertently make the stub package a runtime dependency, which is typically undesirable for production deployments.
- gotcha When using `if TYPE_CHECKING:` blocks for stub imports, `pylint` might complain about undefined variables in the `else` branch. This is because `pylint` may not fully understand the `TYPE_CHECKING` guard.
- gotcha Confusion between `boto3-stubs` and `mypy-boto3` packages is common. While `boto3-stubs` was an alternative, `mypy-boto3` (and its specific service packages like `mypy-boto3-greengrassv2`) is the actively maintained and recommended solution for up-to-date and comprehensive type annotations for `boto3`.
Install
-
pip install mypy-boto3-greengrassv2 -
pip install 'boto3-stubs[greengrassv2]'
Imports
- GreengrassV2Client
from mypy_boto3_greengrassv2.client import GreengrassV2Client
- AssociateClientDeviceWithCoreDeviceEntryTypeDef
from mypy_boto3_greengrassv2.type_defs import AssociateClientDeviceWithCoreDeviceEntryTypeDef
Quickstart
from typing import TYPE_CHECKING
import boto3
if TYPE_CHECKING:
from mypy_boto3_greengrassv2.client import GreengrassV2Client
from mypy_boto3_greengrassv2.type_defs import ListCoreDevicesResponseTypeDef
def list_greengrass_core_devices() -> ListCoreDevicesResponseTypeDef:
# Initialize a boto3 client (runtime object)
client: GreengrassV2Client = boto3.client("greengrassv2")
# Use the type-hinted client
response: ListCoreDevicesResponseTypeDef = client.list_core_devices()
print("Found Greengrass Core Devices:")
for device in response.get("coreDevices", []):
print(f" - {device.get('coreDeviceThingName')} (ARN: {device.get('coreDeviceArn')})")
return response
if __name__ == "__main__":
# This example requires valid AWS credentials configured in your environment
# (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION environment variables)
try:
list_greengrass_core_devices()
except Exception as e:
print(f"An error occurred: {e}")