mypy-boto3-pricing Type Stubs

1.42.82 · active · verified Sat Apr 11

mypy-boto3-pricing provides static type annotations for the `boto3` AWS Pricing service, enhancing development with type checking and IDE autocompletion. It is currently at version 1.42.82, aligning with its corresponding `boto3` version. This package is part of the `mypy-boto3` ecosystem, which automatically generates and releases stubs for all `boto3` services in sync with upstream AWS SDK updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `boto3` Pricing client with type annotations using `mypy-boto3-pricing`. The `TYPE_CHECKING` block allows type checkers to validate your code while avoiding runtime dependencies on `mypy-boto3-pricing` in production. It then calls `get_products` to retrieve pricing information for Amazon EC2 instances running Linux.

import boto3
from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from mypy_boto3_pricing import PricingClient
    from mypy_boto3_pricing.type_defs import GetProductsOutputTypeDef

    client: PricingClient = boto3.client("pricing")

    response: GetProductsOutputTypeDef = client.get_products(
        ServiceCode="AmazonEC2",
        Filters=[
            {"Type": "TERM_MATCH", "Field": "operatingSystem", "Value": "Linux"}
        ],
    )

    for price_list in response.get("PriceList", []):
        print(price_list)

else:
    client = boto3.client("pricing")
    # In a non-type-checking environment, type annotations are stripped.
    # The actual boto3 client is used directly.
    response = client.get_products(
        ServiceCode="AmazonEC2",
        Filters=[
            {"Type": "TERM_MATCH", "Field": "operatingSystem", "Value": "Linux"}
        ],
    )
    for price_list in response.get("PriceList", []):
        print(price_list)

view raw JSON →