mypy-boto3-servicecatalog: ServiceCatalog Type Annotations
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
- breaking Python 3.8 support was removed for all `mypy-boto3` packages (including `mypy-boto3-servicecatalog`) starting with `mypy-boto3-builder` version 8.12.0. Projects using Python 3.8 or older will need to upgrade their Python version.
- breaking In `mypy-boto3-builder` version 8.9.0, some `TypeDef` names for method arguments were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). Conflicting `Extra` postfixes were also moved to the end. This may require updating explicit `TypeDef` imports.
- gotcha `mypy-boto3-servicecatalog` provides type stubs for `boto3` and should not be used as a runtime dependency or for importing classes directly for runtime execution. It is intended solely for static type checking.
- gotcha When using `mypy-boto3` stubs with Pylint, it might complain about undefined variables within `if TYPE_CHECKING:` blocks.
Install
-
pip install mypy-boto3-servicecatalog -
pip install 'boto3-stubs[servicecatalog]'
Imports
- ServiceCatalogClient
from mypy_boto3_servicecatalog.client import ServiceCatalogClient
- AcceptPortfolioShareInputTypeDef
from mypy_boto3_servicecatalog.type_defs import AcceptPortfolioShareInputTypeDef
- AccessLevelFilterKeyType
from mypy_boto3_servicecatalog.literals import AccessLevelFilterKeyType
Quickstart
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}")