mypy-boto3-meteringmarketplace Type Annotations

1.42.58 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a typed `MarketplaceMeteringClient` and make a sample API call like `register_usage`. Type hints are applied for the client and the response, leveraging the installed `mypy-boto3-meteringmarketplace` stubs. Replace placeholder values with actual AWS credentials and valid Marketplace Metering data. The `TYPE_CHECKING` block ensures that stub imports are only active during type checking, avoiding runtime dependencies on stub packages.

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}")

view raw JSON →