mypy-boto3-redshift-serverless Type Stubs
This package provides type annotations for the `boto3` Redshift Serverless service, generated by `mypy-boto3-builder`. It enables static type checking for your `boto3` client calls, enhancing code quality and developer experience. The current version is 1.42.28, closely tracking `boto3` releases, with frequent updates to align with new AWS service features and API changes.
Warnings
- breaking As of `mypy-boto3-builder` version 8.12.0 (affecting `mypy-boto3-*` stub packages 1.42.x and newer), Python 3.8 is no longer supported. Projects must use Python 3.9 or newer.
- breaking The `mypy-boto3-builder` (v8.9.0+) introduced breaking changes to `TypeDef` naming conventions. Argument `TypeDef` names were shortened (e.g., `CreateNamespaceRequestRequestTypeDef` to `CreateNamespaceRequestTypeDef`), and conflicting `Extra` postfixes were moved (e.g., `...ExtraRequestTypeDef` to `...RequestExtraTypeDef`).
- gotcha These packages are type stubs, meaning they provide type annotations but do not include the `boto3` runtime library itself. You must install `boto3` separately alongside the `mypy-boto3-redshift-serverless` package for your code to run.
- gotcha The builder (v8.12.0+) migrated to PEP 561 namespace packages. This change is generally handled by `pip`, but might impact complex environments, especially those using custom `PYTHONPATH` or older `mypy` versions, causing stubs to not be found.
- gotcha Service-specific stub packages follow the `mypy-boto3-<service-name>` naming convention. A common mistake is trying to install or import from just `mypy-boto3` or `<service-name>-stubs`.
Install
-
pip install mypy-boto3-redshift-serverless boto3
Imports
- RedshiftServerlessClient
from mypy_boto3_redshift_serverless.client import RedshiftServerlessClient
- CreateNamespaceRequestRequestTypeDef
from mypy_boto3_redshift_serverless.type_defs import CreateNamespaceRequestRequestTypeDef
Quickstart
import boto3
from mypy_boto3_redshift_serverless.client import RedshiftServerlessClient
from mypy_boto3_redshift_serverless.type_defs import ListNamespacesResponseTypeDef
# Create a boto3 client for Redshift Serverless with type hints
# The 'type: ignore' is sometimes needed if boto3.client does not directly
# return the exact stub type expected by mypy-boto3 in all scenarios,
# or if you are using an older boto3 without full type-hinting support.
redshift_client: RedshiftServerlessClient = boto3.client("redshift-serverless") # type: ignore
def list_redshift_namespaces() -> ListNamespacesResponseTypeDef:
"""
Lists Redshift Serverless namespaces and returns the typed response.
"""
print("Calling list_namespaces...")
response: ListNamespacesResponseTypeDef = redshift_client.list_namespaces()
namespaces = response.get("namespaces", [])
if namespaces:
for ns in namespaces:
print(f" Namespace Name: {ns.get('namespaceName')}, Status: {ns.get('status')}")
else:
print(" No namespaces found.")
return response
if __name__ == "__main__":
# To run this, ensure:
# 1. 'pip install boto3'
# 2. 'pip install mypy-boto3-redshift-serverless'
# 3. AWS credentials are configured (e.g., via ~/.aws/credentials or environment variables)
try:
list_redshift_namespaces()
except Exception as e:
print(f"An error occurred: {e}")
print("Please ensure boto3 is configured with valid AWS credentials and permissions.")