mypy-boto3-pi Type Stubs
This package provides type annotations (stubs) for the 'pi' (Performance Insights) service client within the `boto3` library. It's part of the `mypy-boto3` project, which offers comprehensive type hints for all `boto3` services. The current version is 1.42.3, typically updated frequently to align with new `boto3` and AWS API releases.
Warnings
- breaking Python 3.8 support has been removed. All `mypy-boto3` packages now require Python 3.9 or newer.
- breaking Type definition (TypeDef) naming conventions were changed for consistency. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`. This affects all service packages.
- gotcha This package (`mypy-boto3-pi`) provides only type stubs. It does not include the `boto3` runtime library itself. You must install `boto3` separately for your code to actually interact with AWS services.
- gotcha Service names within AWS (and thus boto3) can change or be deprecated. For example, the `sms-voice` service was removed and replaced by `pinpoint-sms-voice` (mypy-boto3-builder 8.11.0). If a service client fails to resolve types, verify its current name.
- gotcha The `mypy-boto3` project migrated to PEP 561 compliant packages. While generally seamless, if you have complex `mypy` configurations (e.g., `MYPYPATH` environment variables) or are using older `mypy` versions, you might encounter issues with stub discovery.
Install
-
pip install mypy-boto3-pi boto3
Imports
- PIClient
from mypy_boto3_pi.client import PIClient
- GetDimensionKeyDetailsResponseTypeDef
from mypy_boto3_pi.type_defs import GetDimensionKeyDetailsResponseTypeDef
- boto3
import boto3
Quickstart
import boto3
from mypy_boto3_pi.client import PIClient
from mypy_boto3_pi.type_defs import GetDimensionKeyDetailsResponseTypeDef
from typing import TYPE_CHECKING
# Boto3 client without type hints (mypy will infer if stubs are installed)
client = boto3.client('pi')
print(f"Client type (runtime): {type(client)}")
# Type-hinted client for better IDE support and static analysis
pi_client: PIClient = boto3.client('pi')
# Example usage with type-hinted response
# This call requires valid AWS credentials configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION_NAME env vars)
# and an existing DB instance identifier.
# Replace 'db-instance-id' with a real instance if running.
if TYPE_CHECKING:
# Define a dummy response for type checking only
dummy_response: GetDimensionKeyDetailsResponseTypeDef = {
'AlignedEndTime': '', 'AlignedStartTime': '', 'Keys': []
}
try:
response: GetDimensionKeyDetailsResponseTypeDef = pi_client.get_dimension_key_details(
ServiceType='RDS',
Identifier='your-db-instance-id',
Group='DB_INSTANCE',
GroupIdentifier='your-db-instance-id'
)
print("Successfully called get_dimension_key_details (types applied).")
# Further processing with type-hinted response
except Exception as e:
print(f"Could not call AWS PI service: {e}. Ensure 'your-db-instance-id' is valid and credentials are set.")
# Accessing fields with type safety
# if response and response['Keys']:
# print(response['Keys'][0]['Dimensions'])