Type annotations for boto3 ResourceGroups
mypy-boto3-resource-groups provides static type annotations for the AWS Resource Groups service within `boto3`, enabling robust type checking with tools like MyPy, Pyright, and enhanced IDE auto-completion. It is generated by `mypy-boto3-builder` and is part of a larger ecosystem of stub packages that closely track `boto3` releases, with frequent updates for new services and API changes.
Warnings
- breaking Python 3.8 is no longer supported. `mypy-boto3-builder` version 8.12.0 and later, which generates this package, dropped support for Python 3.8. Users must use Python 3.9 or newer.
- breaking TypeDef naming conventions changed in `mypy-boto3-builder` 8.9.0. `TypeDef` for packed method arguments use shorter names if possible (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes were moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` -> `CreateDistributionRequestExtraTypeDef`).
- gotcha These packages provide *only* type annotations, not runtime functionality. You must have the `boto3` library installed alongside `mypy-boto3-resource-groups` for your code to run.
- gotcha While type discovery often works, explicit type annotations for `boto3.client()` and `boto3.resource()` calls are highly recommended, especially for optimal auto-completion and type checking in IDEs like VSCode and PyCharm.
- breaking Migration to PEP 561 packages in `mypy-boto3-builder` 8.12.0. This is a significant internal packaging change for how type stubs are distributed and discovered by type checkers. While generally beneficial, it might affect custom build pipelines or older environments.
Install
-
pip install mypy-boto3-resource-groups -
pip install boto3-stubs[resource-groups]
Imports
- ResourceGroupsClient
from mypy_boto3_resource_groups.client import ResourceGroupsClient
- ResourceGroupsServiceName
from mypy_boto3_resource_groups.literals import ResourceGroupsServiceName
Quickstart
import boto3
from mypy_boto3_resource_groups.client import ResourceGroupsClient
from typing import TYPE_CHECKING
# Ensure boto3 is installed (e.g., pip install boto3)
# Standard boto3 client creation
client = boto3.client("resource-groups")
# Type hint the client for static analysis (e.g., MyPy, IDEs)
# The 'if TYPE_CHECKING:' block ensures this import is only for type checking
# and doesn't cause runtime issues if the stub package isn't installed.
if TYPE_CHECKING:
resource_groups_client: ResourceGroupsClient = client
else:
resource_groups_client = client
# Now 'resource_groups_client' has full type annotations
# For example, calling an operation will show expected arguments and return types.
try:
response = resource_groups_client.list_groups()
print("Successfully listed Resource Groups.")
# Example: print(response['GroupIdentifiers'])
except Exception as e:
print(f"Error listing Resource Groups: {e}")