mypy-boto3-pi Type Stubs

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-pi` for type-hinting your `boto3` PI client. The stubs allow `mypy` and IDEs to provide accurate type information for client methods and their return types, improving code quality and reducing runtime errors. Remember to replace placeholder values like 'your-db-instance-id' and ensure you have valid AWS credentials configured.

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'])

view raw JSON →