mypy-boto3-resourcegroupstaggingapi type stubs
mypy-boto3-resourcegroupstaggingapi provides type annotations for the boto3 AWS Resource Groups Tagging API service (version 1.42.3). It is automatically generated using mypy-boto3-builder 8.12.0, ensuring up-to-date static type checking for your boto3 code. As part of the wider mypy-boto3 ecosystem, it offers robust type hints for clients, paginators, and service-specific TypeDefs, with new releases frequently aligning with boto3 updates.
Warnings
- breaking Starting with `mypy-boto3-builder` version 8.12.0, support for Python 3.8 has been removed for all generated packages, including `mypy-boto3-resourcegroupstaggingapi`. Users on Python 3.8 will need to upgrade to Python 3.9 or newer to use versions generated by `builder` 8.12.0+.
- breaking Builder version 8.9.0 introduced breaking changes to `TypeDef` naming conventions. Type definitions for packed method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and conflicting `Extra` postfixes are moved to the end (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`). This may require updates to explicit `TypeDef` imports in your codebase.
- gotcha This package provides *only* type annotations. You must install the `boto3` library separately for your code to run successfully at runtime. Type checkers will not warn about a missing `boto3` if `mypy-boto3-resourcegroupstaggingapi` is installed.
- gotcha Beginning with `mypy-boto3-builder` 8.12.0, packages migrated to follow PEP 561. This change improves compatibility and discovery for type checkers. Ensure your type checker (e.g., mypy, pyright) is configured to correctly find and utilize PEP 561 compliant stub packages.
- gotcha For IDEs like PyCharm, or in scenarios where memory usage is critical, using `boto3-stubs-lite` (e.g., `pip install 'boto3-stubs-lite[resourcegroupstaggingapi]'`) might be recommended over the full `boto3-stubs` or standalone packages. The lite version is more RAM-friendly but requires explicit type annotations for `session.client`/`resource` calls.
- deprecated While not directly affecting `ResourceGroupsTaggingAPI`, a change in `mypy-boto3-builder` 8.11.0 removed support for the `sms-voice` service, advising users to switch to `pinpoint-sms-voice`. This highlights that AWS service deprecations or renaming will propagate to `mypy-boto3` generated stubs, potentially requiring users to update service names in their code.
Install
-
pip install mypy-boto3-resourcegroupstaggingapi boto3
Imports
- ResourceGroupsTaggingAPIClient
from mypy_boto3_resourcegroupstaggingapi import ResourceGroupsTaggingAPIClient
- GetResourcesPaginator
from mypy_boto3_resourcegroupstaggingapi.paginator import GetResourcesPaginator
- ComplianceDetailsTypeDef
from mypy_boto3_resourcegroupstaggingapi.type_defs import ComplianceDetailsTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_resourcegroupstaggingapi import ResourceGroupsTaggingAPIClient
from mypy_boto3_resourcegroupstaggingapi.type_defs import TagResourcesOutputTypeDef
def get_resources_with_tags(region_name: str, tags: dict[str, str]) -> TagResourcesOutputTypeDef:
# Initialize the boto3 client with type annotation for mypy-boto3
client: ResourceGroupsTaggingAPIClient = boto3.client(
"resourcegroupstaggingapi",
region_name=region_name
)
# Prepare tag filters for the GetResources operation
tag_filters = [{
"Key": k,
"Values": [v]
} for k, v in tags.items()]
# Get resources with specified tags
response = client.get_resources(
TagFilters=tag_filters
)
print(f"Found {len(response.get('ResourceTagMappingList', []))} resources.")
for resource_mapping in response.get('ResourceTagMappingList', []):
print(f" Resource ARN: {resource_mapping.get('ResourceARN')}")
print(f" Tags: {resource_mapping.get('Tags')}")
return response
# Example usage:
if __name__ == "__main__":
# Replace 'us-east-1' with your desired AWS region
# Make sure your AWS credentials are configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION_NAME env vars or ~/.aws/credentials)
try:
result = get_resources_with_tags(
region_name="us-east-1",
tags={
"Environment": "Production",
"Project": "MyProject"
}
)
except Exception as e:
print(f"An error occurred: {e}")