mypy-boto3-s3tables Type Annotations
mypy-boto3-s3tables provides type annotations for the `boto3` AWS SDK's S3Tables service. Generated by `mypy-boto3-builder`, it enhances developer experience by enabling static type checking with tools like MyPy and improving IDE features such as autocompletion and error detection for `boto3` calls. The package versions are synchronized with `boto3` releases, ensuring a regular and active update cadence.
Warnings
- breaking Python 3.8 support has been removed as of `mypy-boto3-builder` version 8.12.0. The package now requires Python 3.9 or newer.
- breaking TypeDef naming conventions changed in `mypy-boto3-builder` version 8.9.0. This might affect custom code that explicitly references generated TypedDicts, for instance, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`.
- gotcha It's crucial to install `boto3` (the actual AWS SDK) and `mypy` (the type checker) alongside `mypy-boto3-s3tables`. Without them, the stubs will not provide runtime functionality or be utilized for static analysis.
- gotcha Mismatching versions between `boto3` and `mypy-boto3-s3tables` can lead to incorrect type hints or missing methods. The stub package aims to match the corresponding `boto3` version.
- gotcha To prevent `mypy-boto3-s3tables` from becoming a runtime dependency and to import only type-specific objects, wrap type imports within an `if TYPE_CHECKING:` block.
- gotcha PyCharm has known performance issues with `Literal` overloads in type stub packages. For PyCharm users, `boto3-stubs-lite` might offer a more responsive experience at the cost of requiring more explicit type annotations.
Install
-
pip install mypy-boto3-s3tables boto3 mypy -
pip install 'boto3-stubs[s3tables]' boto3 mypy
Imports
- S3TablesClient
from mypy_boto3_s3tables.client import S3TablesClient
- CreateNamespaceRequestTypeDef
from mypy_boto3_s3tables.type_defs import CreateNamespaceRequestTypeDef
Quickstart
from typing import TYPE_CHECKING
import boto3
from boto3.session import Session
if TYPE_CHECKING:
from mypy_boto3_s3tables.client import S3TablesClient
from mypy_boto3_s3tables.type_defs import ListNamespacesOutputTypeDef
def get_s3tables_client() -> 'S3TablesClient':
"""Initializes and returns a type-hinted S3Tables client."""
session: Session = boto3.session.Session()
client: S3TablesClient = session.client('s3tables')
return client
def list_s3tables_namespaces() -> None:
"""Lists S3Tables namespaces with type checking."""
client = get_s3tables_client()
# Use a dummy list for illustration, as actual AWS calls require credentials
# If you have AWS credentials configured, uncomment the line below:
# response: ListNamespacesOutputTypeDef = client.list_namespaces()
# Example with a mock response for type checking demonstration:
response: ListNamespacesOutputTypeDef = {
'namespaces': [
{'namespaceArn': 'arn:aws:s3tables:REGION:ACCOUNT:namespace/example1', 'namespaceName': 'example1'},
{'namespaceArn': 'arn:aws:s3tables:REGION:ACCOUNT:namespace/example2', 'namespaceName': 'example2'}
],
'ResponseMetadata': {
'RequestId': 'example-request-id',
'HTTPStatusCode': 200,
'HTTPHeaders': {},
'RetryAttempts': 0
}
}
for namespace in response['namespaces']:
print(f"Namespace ARN: {namespace['namespaceArn']}, Name: {namespace['namespaceName']}")
if __name__ == "__main__":
list_s3tables_namespaces()