mypy-boto3-redshift-data Type Stubs
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
- breaking Starting with version 8.12.0 of `mypy-boto3-builder` (which generates this stub), support for Python 3.8 has been removed. Projects using these stubs must target Python 3.9 or newer.
- breaking Version 8.9.0 introduced changes to TypedDict naming conventions to improve consistency and resolve conflicts. Some TypeDef names may have been shortened or have `Extra` moved to the end.
- gotcha This package provides only type stubs and does not include the `boto3` runtime library itself. `boto3` must be installed separately for your code to execute.
- gotcha For the most accurate type checking, the version of `mypy-boto3-redshift-data` should ideally match or be close to your installed `boto3` version, as stubs are generated for specific `boto3` releases.
Install
-
pip install mypy-boto3-redshift-data
Imports
- RedshiftDataClient
from mypy_boto3_redshift_data import RedshiftDataClient
- ExecuteStatementResponseTypeDef
from mypy_boto3_redshift_data.type_defs import ExecuteStatementResponseTypeDef
Quickstart
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.")