Type Annotations for Boto3 Kinesis

1.42.41 · active · verified Thu Apr 09

mypy-boto3-kinesis provides Mypy-compatible type annotations for the Boto3 Kinesis service. It enhances development with AWS Boto3 by offering static type checking, auto-completion, and improved code navigation for Kinesis clients, paginators, waiters, literals, and type definitions. The current version is 1.42.41, generated by mypy-boto3-builder 8.12.0, and new versions are released in sync with Boto3 updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a Boto3 Kinesis client with type annotations and list available Kinesis streams. Explicit type hints for the client and response structures provide static analysis benefits. Ensure AWS credentials and region are configured in your environment for the code to run successfully.

import boto3
from mypy_boto3_kinesis.client import KinesisClient
from mypy_boto3_kinesis.type_defs import ListStreamsOutputTypeDef
import os

def list_kinesis_streams() -> ListStreamsOutputTypeDef:
    # Ensure boto3 is configured, e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY,
    # and AWS_REGION environment variables or ~/.aws/credentials
    # The 'client' variable is explicitly type-hinted for mypy/IDE benefit
    client: KinesisClient = boto3.client("kinesis", region_name=os.environ.get('AWS_REGION', 'us-east-1'))
    
    response: ListStreamsOutputTypeDef = client.list_streams()
    print("Kinesis Streams:")
    for stream_name in response.get("StreamNames", []):
        print(f"- {stream_name}")
    return response

if __name__ == "__main__":
    # Example usage requires AWS credentials and region to be set up
    # For demonstration, ensure environment variables are set or remove this check
    if not os.environ.get('AWS_ACCESS_KEY_ID') or not os.environ.get('AWS_SECRET_ACCESS_KEY'):
        print("Please set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.")
        print("Also, optionally set AWS_REGION (defaults to 'us-east-1').")
    else:
        try:
            list_kinesis_streams()
        except Exception as e:
            print(f"An error occurred: {e}")

view raw JSON →