Type Annotations for Boto3 Kinesis
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
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0 (and consequently affects `mypy-boto3-kinesis`). Users on Python 3.8 should upgrade their Python version.
- breaking In `mypy-boto3-builder` version 8.9.0, some `TypeDef` names were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). While this example is for CloudFront, similar changes might affect Kinesis-specific `TypeDefs` if they followed the same pattern.
- gotcha This package provides *type annotations* for Boto3; it does not replace the actual `boto3` library, which must be installed separately and is required at runtime for your application to function.
- gotcha When using `boto3.client()` or `boto3.session.client()` without installing `boto3-stubs` (i.e., only `mypy-boto3-kinesis`), explicit type annotations are often necessary for optimal IDE auto-completion and static analysis. For example: `client: KinesisClient = boto3.client("kinesis")`.
- gotcha For Pylint compatibility and to avoid `undefined-variable` warnings when using `TYPE_CHECKING` for conditional imports, you might need to assign `object` to your client types in the non-`TYPE_CHECKING` block.
Install
-
pip install boto3 mypy-boto3-kinesis -
pip install boto3 'boto3-stubs[kinesis]'
Imports
- KinesisClient
from mypy_boto3_kinesis.client import KinesisClient
- StreamExistsWaiter
from mypy_boto3_kinesis.waiters import StreamExistsWaiter
- ConsumerStatusType
from mypy_boto3_kinesis.literals import ConsumerStatusType
- ListStreamsOutputTypeDef
from mypy_boto3_kinesis.type_defs import ListStreamsOutputTypeDef
Quickstart
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}")