Mypy Boto3 Timestream Write Stubs
mypy-boto3-timestream-write provides type annotations for the `boto3` TimestreamWrite service (version 1.42.3), enabling static analysis, improved IDE autocompletion, and robust type checking for your AWS interactions. This package is generated by `mypy-boto3-builder` (version 8.12.0) and is updated frequently to stay in sync with `boto3` and `botocore` releases.
Warnings
- breaking Python 3.8 support has been removed for all `mypy-boto3` packages with `mypy-boto3-builder` version 8.12.0. Users on Python 3.8 should update to Python 3.9 or newer.
- breaking All `mypy-boto3` packages, including `mypy-boto3-timestream-write`, migrated to PEP 561-compliant packaging with `mypy-boto3-builder` version 8.12.0. This changes how type checkers locate stubs. While usually seamless with `pip`, ensure your build tools and environments correctly discover PEP 561 packages.
- breaking Some `TypeDef` names were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`) and conflicting `Extra` postfixes moved with `mypy-boto3-builder` version 8.9.0. If you explicitly import `TypeDef`s, these changes may break your code.
- gotcha This package provides *only* type annotations for `boto3` and `botocore`. It does not include `boto3` itself, which must be installed separately for your code to run at runtime.
- gotcha For optimal type checking and IDE autocompletion, especially in VSCode and PyCharm, it is highly recommended to explicitly annotate the type of `boto3.client()` calls (e.g., `client: TimestreamWriteClient = boto3.client(...)`). While some IDEs offer implicit type discovery, explicit annotations provide the most consistent experience.
- gotcha PyCharm users might experience slow performance or high CPU usage due to how it handles `Literal` overloads in `mypy-boto3` packages. Using `boto3-stubs-lite` (if available for the service) or disabling PyCharm's internal type checker in favor of `mypy` or `pyright` is often recommended as a workaround.
Install
-
pip install mypy-boto3-timestream-write boto3
Imports
- TimestreamWriteClient
from mypy_boto3_timestream_write.client import TimestreamWriteClient
- WriteRecordsRequestRequestTypeDef
from mypy_boto3_timestream_write.type_defs import WriteRecordsRequestRequestTypeDef
- RecordsOutputTypeDef
from mypy_boto3_timestream_write.type_defs import RecordsOutputTypeDef
Quickstart
import boto3
import os
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_timestream_write.client import TimestreamWriteClient
from mypy_boto3_timestream_write.type_defs import DescribeEndpointsResponseTypeDef
# It's recommended to install boto3 in addition to mypy-boto3-timestream-write
# pip install boto3 mypy-boto3-timestream-write
# Initialize a boto3 client with explicit type annotation
# This helps IDEs and type checkers provide accurate suggestions
client: TimestreamWriteClient = boto3.client(
"timestream-write",
region_name=os.environ.get('AWS_REGION', 'us-east-1'),
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'YOUR_ACCESS_KEY'),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'YOUR_SECRET_KEY')
)
try:
# Use a simple method to demonstrate type checking
response: DescribeEndpointsResponseTypeDef = client.describe_endpoints()
print("Timestream Write Endpoints:")
for endpoint in response.get('Endpoints', []):
print(f" Address: {endpoint.get('Address')}, CachePeriodInMinutes: {endpoint.get('CachePeriodInMinutes')}")
except Exception as e:
print(f"Error describing endpoints: {e}")
# Example of using a TypedDict
# from mypy_boto3_timestream_write.type_defs import WriteRecordsRequestRequestTypeDef
# write_request: WriteRecordsRequestRequestTypeDef = {
# "DatabaseName": "my_database",
# "TableName": "my_table",
# "Records": [
# {
# "MeasureName": "cpu_utilization",
# "MeasureValue": "10.5",
# "MeasureValueType": "DOUBLE",
# "Time": "1678886400000",
# "TimeUnit": "MILLISECONDS"
# }
# ]
# }
# print(f"\nSample WriteRecordsRequestRequestTypeDef: {write_request}")