mypy-boto3-keyspaces Type Stubs for AWS Keyspaces

1.42.31 · active · verified Sat Apr 11

mypy-boto3-keyspaces provides precise type annotations for the `boto3` AWS SDK, specifically for the Keyspaces (for Apache Cassandra) service. This library enables static type checking with tools like `mypy`, improving code reliability and developer experience when interacting with AWS Keyspaces. The current version is 1.42.31, released frequently to align with `boto3` and `botocore` updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-keyspaces` with `boto3`. The `if TYPE_CHECKING:` block ensures that the type stub imports are only processed by static analysis tools like `mypy`, avoiding any runtime overhead. Remember to replace `my_keyspace` with an actual Keyspaces keyspace and ensure AWS credentials are configured for the `boto3` client to function correctly.

import boto3
from mypy_boto3_keyspaces.client import KeyspacesClient
from typing import TYPE_CHECKING
import os

# Configure AWS credentials and region if not already set via environment variables or ~/.aws/credentials
# For example, using environment variables:
# os.environ['AWS_ACCESS_KEY_ID'] = 'YOUR_ACCESS_KEY'
# os.environ['AWS_SECRET_ACCESS_KEY'] = 'YOUR_SECRET_KEY'
# os.environ['AWS_REGION'] = 'us-east-1'

if TYPE_CHECKING:
    # mypy will use these imports for type checking
    client: KeyspacesClient = boto3.client("keyspaces", region_name=os.environ.get('AWS_REGION', 'us-east-1'))
    
    # Example: List tables (requires appropriate IAM permissions)
    try:
        response = client.list_tables(keyspaceName='my_keyspace')
        print("Tables:", response.get("TableNames"))
    except Exception as e:
        print(f"Error listing tables: {e}")

else:
    # Runtime code doesn't strictly need the mypy-boto3 imports
    client = boto3.client("keyspaces", region_name=os.environ.get('AWS_REGION', 'us-east-1'))
    
    # Example: List tables
    try:
        response = client.list_tables(keyspaceName='my_keyspace')
        print("Tables:", response.get("TableNames"))
    except Exception as e:
        print(f"Error listing tables: {e}")

print("Code execution finished. Run `mypy your_script.py` for type checking.")

view raw JSON →