mypy-boto3-redshift-data Type Stubs

1.42.3 · active · verified Thu Apr 09

mypy-boto3-redshift-data provides high-quality type annotations for the `boto3` RedshiftDataAPIService, enhancing developer experience with static type checking for AWS interactions. It's part of the `mypy-boto3` ecosystem, which generates stubs for all `boto3` services. Releases are frequent, typically following new `boto3` versions and `mypy-boto3-builder` updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a `boto3` RedshiftData client and use it with type hints provided by `mypy-boto3-redshift-data`. It includes an example `execute_statement` call, showcasing how input arguments and output responses benefit from static type checking. Remember to install `boto3` separately.

import boto3
from mypy_boto3_redshift_data import RedshiftDataClient
from mypy_boto3_redshift_data.type_defs import ExecuteStatementResponseTypeDef
import os

# Instantiate the boto3 client, which will be augmented with type hints
# from mypy-boto3-redshift-data for static analysis.
client: RedshiftDataClient = boto3.client("redshift-data")

# Example of executing a Redshift Data API statement.
# Replace with your actual cluster, database, and SQL for a successful run.
cluster_identifier = os.environ.get("REDSHIFT_CLUSTER_IDENTIFIER", "your-redshift-cluster-identifier")
database = os.environ.get("REDSHIFT_DATABASE", "dev")
db_user = os.environ.get("REDSHIFT_DB_USER", "awsuser")
sql_statement = "SELECT 1;" # A simple, safe statement

try:
    # mypy will check arguments and the response type
    response: ExecuteStatementResponseTypeDef = client.execute_statement(
        ClusterIdentifier=cluster_identifier,
        Database=database,
        DbUser=db_user,
        Sql=sql_statement,
        WithEvent=False # Example of an optional parameter with type checking
    )
    print(f"Statement ID: {response['Id']}")
    # Accessing an optional key safely with .get()
    print(f"Statement status: {response.get('Status', 'UNKNOWN')}")

    # Mypy would flag if you tried to access 'response["NonExistentKey"]'
    # or used a wrong type for an argument to client.execute_statement.

except Exception as e:
    print(f"Error executing statement: {e}")
    print("Please ensure environment variables REDSHIFT_CLUSTER_IDENTIFIER, REDSHIFT_DATABASE, REDSHIFT_DB_USER are set if expecting a successful execution.")

print("\nType checking for RedshiftDataClient is enabled.")

view raw JSON →