Type Annotations for boto3 SecurityLake
mypy-boto3-securitylake provides static type annotations for the AWS SDK for Python (boto3) specifically for the SecurityLake service. It enhances development experience by enabling IDE autocompletion and static type checking with tools like MyPy, addressing the dynamic nature of boto3's client generation. This package is generated by the `mypy-boto3-builder` and is currently at version 1.42.3, typically released in sync with `boto3` updates.
Warnings
- breaking Python 3.8 support was removed with `mypy-boto3-builder` version 8.12.0. This `mypy-boto3-securitylake` package (version 1.42.3) requires Python 3.9 or newer.
- breaking Beginning with `mypy-boto3-builder` version 8.9.0, there were breaking changes to TypeDef naming conventions, including shorter names for packed method arguments and moving the `Extra` postfix. This might require updating existing type annotations in your code.
- gotcha This package provides type stubs for `boto3`. You must also install `boto3` itself for your code to run, as `mypy-boto3-securitylake` only provides the type definitions, not the AWS SDK implementation.
- gotcha To ensure accurate type hints and autocompletion, keep `mypy-boto3-securitylake` and `boto3` versions synchronized. Significant version mismatches can lead to incorrect type information or missing definitions.
- gotcha Some IDEs (e.g., PyCharm) may experience slow performance or high CPU usage when processing the extensive type information from `boto3-stubs` (the umbrella project for `mypy-boto3-*` packages).
- gotcha For optimal autocompletion and type inference in IDEs like VSCode and PyCharm, it is often beneficial to explicitly annotate the type of `boto3.client` and `boto3.resource` calls with the corresponding `mypy_boto3_securitylake` client or resource type.
Install
-
pip install mypy-boto3-securitylake boto3
Imports
- SecurityLakeClient
from mypy_boto3_securitylake.client import SecurityLakeClient
- ListDataLakesResponseTypeDef
from mypy_boto3_securitylake.type_defs import ListDataLakesResponseTypeDef
Quickstart
import boto3
from mypy_boto3_securitylake.client import SecurityLakeClient
from mypy_boto3_securitylake.type_defs import ListDataLakesResponseTypeDef
import os
def get_securitylake_data_lakes() -> ListDataLakesResponseTypeDef:
# It's recommended to explicitly type the client for best IDE support
client: SecurityLakeClient = boto3.client(
"securitylake",
region_name=os.environ.get('AWS_REGION', 'us-east-1'),
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', '')
)
response = client.list_data_lakes()
return response
if __name__ == "__main__":
data_lakes = get_securitylake_data_lakes()
print(f"Found {len(data_lakes.get('DataLakes', []))} data lakes:")
for dl in data_lakes.get('DataLakes', []):
print(f"- Region: {dl['Region']}, ARN: {dl['DataLakeArn']}")