mypy-boto3-servicecatalog: ServiceCatalog Type Annotations

1.42.3 · active · verified Sat Apr 11

mypy-boto3-servicecatalog provides comprehensive type annotations for the `boto3` ServiceCatalog service, enhancing static analysis, autocompletion, and error detection for `boto3` code. It is currently at version 1.42.3 and is generated by the `mypy-boto3-builder` to align with `boto3` releases, ensuring up-to-date type definitions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-servicecatalog` to add type hints to a `boto3` ServiceCatalog client. It defines a function that lists Service Catalog products, explicitly typing the client and response objects to leverage static analysis. The `TYPE_CHECKING` block ensures the stubs are only loaded during static analysis, not at runtime.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_servicecatalog.client import ServiceCatalogClient
    from mypy_boto3_servicecatalog.type_defs import SearchProductsOutputTypeDef

def list_servicecatalog_products() -> list[str]:
    """Lists Service Catalog products with type hints."""
    # boto3 client is dynamically typed at runtime, stubs provide static types
    client: ServiceCatalogClient = boto3.client("servicecatalog")
    
    response: SearchProductsOutputTypeDef = client.search_products()
    product_names = []
    for product_view in response.get('ProductViewAggregations', []):
        if 'ProductViewSummary' in product_view and 'Name' in product_view['ProductViewSummary']:
            product_names.append(product_view['ProductViewSummary']['Name'])
    return product_names

if __name__ == "__main__":
    print("Attempting to list Service Catalog products (requires AWS credentials)...")
    try:
        products = list_servicecatalog_products()
        if products:
            print(f"Found {len(products)} products:")
            for product in products:
                print(f"- {product}")
        else:
            print("No Service Catalog products found.")
    except Exception as e:
        print(f"Error listing products: {e}")

view raw JSON →