mypy-boto3-redshift Type Annotations
mypy-boto3-redshift provides explicit type annotations for the `boto3` Redshift service, enhancing static analysis with tools like mypy, pyright, and various IDEs. Generated by `mypy-boto3-builder`, it offers comprehensive type hinting for Redshift clients, paginators, waiters, and associated type definitions. The library is actively maintained and kept in sync with upstream `boto3` releases.
Warnings
- breaking Support for Python 3.8 was removed starting with `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 should either upgrade their Python version or pin `mypy-boto3-redshift` (and `boto3-stubs` if used) to an older version (e.g., <8.12.0 of the builder generation, which corresponds to `mypy-boto3-redshift` version prior to 1.42.42).
- breaking The `mypy-boto3` family of packages (including `mypy-boto3-redshift`) migrated to PEP 561 compliant packages with `mypy-boto3-builder` 8.12.0. This change affects how type checkers discover stubs and generally improves compatibility, but older type checker configurations or environments might need adjustments.
- gotcha `mypy-boto3-redshift` provides only type *stubs*. For your Python code to actually interact with AWS Redshift, you must have the `boto3` library itself installed in your environment. These stubs enhance `boto3` with type checking, but do not replace it.
- gotcha When using `mypy-boto3` stubs with PyCharm, there can be performance issues and high CPU usage due to PyCharm's handling of `Literal` overloads (issue PY-40997). This can lead to a slow IDE experience.
- breaking With `mypy-boto3-builder` version 8.9.0, some generated `TypeDef` names were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`) and conflicting `Extra` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`). Code explicitly importing or referencing these generated type definition names may break.
Install
-
pip install mypy-boto3-redshift -
pip install 'boto3-stubs[redshift]' -
pip install mypy-boto3 boto3
Imports
- RedshiftClient
from mypy_boto3_redshift.client import RedshiftClient
- DescribeClustersResponseTypeDef
from mypy_boto3_redshift.type_defs import DescribeClustersResponseTypeDef
Quickstart
import boto3
from mypy_boto3_redshift.client import RedshiftClient
from mypy_boto3_redshift.type_defs import DescribeClustersResponseTypeDef
def get_redshift_client() -> RedshiftClient:
"""Initializes and returns a type-hinted Redshift client."""
# boto3.client returns a Client, which mypy_boto3_redshift annotates
client: RedshiftClient = boto3.client("redshift")
return client
def describe_redshift_clusters(client: RedshiftClient) -> DescribeClustersResponseTypeDef:
"""Describes Redshift clusters with type hinting."""
response: DescribeClustersResponseTypeDef = client.describe_clusters(
ClusterIdentifier='my-redshift-cluster' # Replace with actual cluster ID
)
return response
if __name__ == "__main__":
redshift_client = get_redshift_client()
try:
clusters_info = describe_redshift_clusters(redshift_client)
print(f"Found {len(clusters_info['Clusters'])} Redshift clusters.")
for cluster in clusters_info['Clusters']:
print(f" - Cluster: {cluster['ClusterIdentifier']} Status: {cluster['ClusterStatus']}")
except Exception as e:
print(f"An error occurred: {e}")