mypy-boto3-marketplace-catalog Type Annotations

1.42.41 · active · verified Sat Apr 11

mypy-boto3-marketplace-catalog provides type annotations for the `boto3` AWS Marketplace Catalog service, ensuring type-safe interactions with the AWS API. It is part of the `mypy-boto3` project, which frequently releases updates to keep pace with `boto3` and `botocore` changes, generated using `mypy-boto3-builder 8.12.0`.

Warnings

Install

Imports

Quickstart

This example demonstrates how to use `mypy-boto3-marketplace-catalog` to type-hint a `boto3` Marketplace Catalog client and its responses. It lists entities of type 'ContainerProduct' from the 'AWSMarketplace' catalog. The `if TYPE_CHECKING:` block ensures that the type stub imports are only processed by type checkers and not during runtime, preventing unnecessary runtime dependencies.

import os
from typing import TYPE_CHECKING
import boto3

if TYPE_CHECKING:
    from mypy_boto3_marketplace_catalog.client import MarketplaceCatalogClient
    from mypy_boto3_marketplace_catalog.type_defs import ListEntitiesResponseTypeDef

# Ensure boto3 is configured, e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, etc.
# For local testing, ensure dummy credentials or a valid AWS config exist.
# os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY')
# os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET')
# os.environ['AWS_SESSION_TOKEN'] = os.environ.get('AWS_SESSION_TOKEN', 'DUMMY_TOKEN')
# os.environ['AWS_DEFAULT_REGION'] = os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')

def list_marketplace_entities() -> list[str]:
    client: 'MarketplaceCatalogClient' = boto3.client('marketplace-catalog')
    try:
        response: 'ListEntitiesResponseTypeDef' = client.list_entities(
            Catalog='AWSMarketplace', EntityType='ContainerProduct'
        )
        entity_ids = [entity['EntityId'] for entity in response.get('EntitySummaryList', [])]
        print(f"Found {len(entity_ids)} Marketplace Catalog entities.")
        return entity_ids
    except Exception as e:
        print(f"Error listing entities: {e}")
        return []

if __name__ == '__main__':
    entities = list_marketplace_entities()
    if entities:
        print(f"First 3 entity IDs: {entities[:3]}")

view raw JSON →