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.
Common errors
-
ModuleNotFoundError: No module named 'mypy_boto3_redshift_data'
cause The `mypy-boto3-redshift-data` package, which provides type annotations for the Redshift Data API service, is not installed in the active Python environment.fixInstall the package using pip: `python -m pip install mypy-boto3-redshift-data` or `python -m pip install 'boto3-stubs[redshift-data]'` for the full `boto3-stubs` package with extras. -
mypy error: 'Client' has no attribute 'execute_statement'
cause Mypy is not correctly inferring the type of the `boto3` Redshift Data API client, often because the type stubs are not being picked up or an explicit type annotation is missing, leading to a generic `boto3.client` return type without service-specific methods.fixExplicitly annotate the `boto3` client with `RedshiftDataAPIServiceClient` imported from `mypy_boto3_redshift_data.client` to ensure mypy uses the correct stub definitions: `from mypy_boto3_redshift_data.client import RedshiftDataAPIServiceClient import boto3 client: RedshiftDataAPIServiceClient = boto3.client("redshift-data") client.execute_statement(...)` -
mypy error: Argument "service_name" to "client" of "boto3.session.Session" has incompatible type "Literal['redshift-data']"; expected "Union[Literal['...'], str]"
cause This mypy error indicates a type mismatch when passing the service name literal 'redshift-data' to `boto3.client()`. It suggests that mypy, in combination with the installed stubs, expects a broader type for `service_name` or that the specific stub for 'redshift-data' is not fully recognized in the type union.fixEnsure `boto3-stubs` is correctly installed, potentially reinstalling it. Also, consider updating `mypy` and `boto3-stubs` to their latest versions to ensure compatibility. If the issue persists, explicitly import `RedshiftDataAPIServiceServiceName` from `mypy_boto3_redshift_data.literals` and use it for the service name, or cast the service name literal to `str` if `mypy` is overly strict: `from mypy_boto3_redshift_data.literals import RedshiftDataAPIServiceServiceName import boto3 client = boto3.client(RedshiftDataAPIServiceServiceName)`
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 boto3.client import 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.")