mypy-boto3-meteringmarketplace Type Annotations
mypy-boto3-meteringmarketplace provides comprehensive type annotations for the `boto3` MarketplaceMetering service (version 1.42.58). Generated by `mypy-boto3-builder`, these stubs enhance development with static type checking, auto-completion, and error detection in IDEs and tools like mypy and pyright. The library frequently updates to stay in sync with `boto3` and `botocore` releases, ensuring up-to-date type definitions for AWS SDK interactions.
Warnings
- breaking Python 3.8 support was removed in `mypy-boto3-builder` version 8.12.0 and later. Ensure your project runs on Python 3.9 or higher. [cite: 8.12.0 release notes]
- breaking Starting with `mypy-boto3-builder` 8.9.0, some `TypeDef` names were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`) and conflicting `TypeDef` postfixes were reordered. [cite: 8.9.0 release notes]
- gotcha The `mypy-boto3-builder` project migrated to PEP 561 packages in version 8.12.0. This might affect how type checkers discover stubs in complex project setups or older environments. [cite: 8.12.0 release notes]
- gotcha If you experience slow performance or high CPU usage with PyCharm, especially with `Literal` overloads, it is recommended to use the `boto3-stubs-lite` version instead. This offers a more RAM-friendly experience at the cost of requiring more explicit type annotations.
- gotcha For Pylint compatibility, if it complains about undefined variables when using type hints, consider wrapping your stub imports with `if TYPE_CHECKING:` blocks and assigning `object` to the types outside the block.
- gotcha AWS service names can change or be deprecated (e.g., `sms-voice` was replaced by `pinpoint-sms-voice` in `mypy-boto3-builder` 8.11.0). If a service client or type definition is not found, verify the current service name in `boto3` documentation. [cite: 8.11.0 release notes]
Install
-
pip install mypy-boto3-meteringmarketplace -
pip install boto3 mypy-boto3-meteringmarketplace
Imports
- MarketplaceMeteringClient
from mypy_boto3_meteringmarketplace.client import MarketplaceMeteringClient
- RegisterUsageOutputTypeDef
from mypy_boto3_meteringmarketplace.type_defs import RegisterUsageOutputTypeDef
Quickstart
import os
import boto3
from typing import TYPE_CHECKING
# Ensure you have boto3 installed for runtime and mypy-boto3-meteringmarketplace for type checking
if TYPE_CHECKING:
from mypy_boto3_meteringmarketplace.client import MarketplaceMeteringClient
from mypy_boto3_meteringmarketplace.type_defs import RegisterUsageOutputTypeDef
# Standard boto3 client creation (runtime)
client: MarketplaceMeteringClient = boto3.client(
"meteringmarketplace",
region_name=os.environ.get("AWS_REGION", "us-east-1"),
aws_access_key_id=os.environ.get("AWS_ACCESS_KEY_ID", ""),
aws_secret_access_key=os.environ.get("AWS_SECRET_ACCESS_KEY", ""),
aws_session_token=os.environ.get("AWS_SESSION_TOKEN", ""),
)
try:
# Example: Registering usage. Note: ProductCode and UsageAllocations are required.
# This is a dummy example; replace with actual logic and valid data.
product_code = "YOUR_PRODUCT_CODE"
usage_allocations = [
{"AllocatedUsageQuantity": 1, "Tags": [{"Key": "Dim", "Value": "Val"}]}
]
response: RegisterUsageOutputTypeDef = client.register_usage(
ProductCode=product_code,
UsageAllocations=usage_allocations,
UsageQuantity=1, # Deprecated, UsageAllocations is preferred
Timestamp=int(os.time.time()),
)
print(f"Usage registration successful: {response.get('UsageMeteringRecordId')}")
except client.exceptions.ProductCodeNotFoundException:
print(f"Error: Product code '{product_code}' not found.")
except Exception as e:
print(f"An error occurred: {e}")