mypy-boto3-pricing Type Stubs
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
- breaking Version 8.12.0 of `mypy-boto3-builder` (which generates these stubs) removed support for Python 3.8 across all `mypy-boto3` packages. Projects targeting Python 3.8 must use an older version of `mypy-boto3-pricing` or upgrade to Python 3.9 or newer. [cite: 8.12.0 release notes]
- breaking Breaking changes in TypeDef naming conventions were introduced in `mypy-boto3-builder` 8.9.0. Some TypeDefs for method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and conflicting TypeDef `Extra` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` to `CreateDistributionRequestExtraTypeDef`). If you explicitly reference these TypeDef names, your code may break. [cite: 8.9.0 release notes, 3]
- gotcha PyCharm users might experience slow performance and high CPU usage due to `Literal` overloads. It is recommended to use `boto3-stubs-lite` (if available for the service) or disable PyCharm's internal type checker and rely on external tools like `mypy` or `pyright`.
- gotcha While `mypy` and PyCharm often infer types correctly, VSCode users may need to provide explicit type annotations for `boto3.client`, `boto3.session.client`, `client.get_waiter`, and `client.get_paginator` calls to ensure full code autocompletion and correct type hints.
- gotcha When using `typing.TYPE_CHECKING` to conditionally import type stubs and avoid production dependencies, Pylint may report 'undefined variable' errors for the type-annotated objects in the runtime block.
Install
-
pip install mypy-boto3-pricing boto3
Imports
- PricingClient
from mypy_boto3_pricing import PricingClient
- DescribeServicesPaginator
from mypy_boto3_pricing.paginator import DescribeServicesPaginator
- AttributeValueTypeDef
from mypy_boto3_pricing.type_defs import AttributeValueTypeDef
Quickstart
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)