mypy-boto3-efs Type Annotations
mypy-boto3-efs provides type annotations for the boto3 EFS service, generated using the `mypy-boto3-builder`. These stubs enhance type checking for `boto3` code, allowing tools like MyPy to catch type-related errors before runtime. The current version is 1.42.3, and it follows the frequent release cadence of its builder.
Warnings
- breaking Python 3.8 is no longer supported. `mypy-boto3-builder` version 8.12.0 (and subsequent versions which generate `mypy-boto3-efs` 1.42.3+) removed support for Python 3.8. Ensure your environment uses Python 3.9 or newer.
- gotcha These packages provide only type stubs. They do not replace `boto3`. You must install both `boto3` and the `mypy-boto3-efs` package to get full type checking alongside runtime functionality.
- breaking TypeDef naming conventions changed in `mypy-boto3-builder` 8.9.0. This can affect code that directly references generated TypeDefs, potentially shortening names like `CreateDistributionRequestRequestTypeDef` to `CreateDistributionRequestTypeDef`. While `mypy-boto3-efs` might not have many double-suffixed types, it's a general builder change.
- breaking Migration to PEP 561 packages in `mypy-boto3-builder` 8.12.0. This changes how stubs are packaged and discovered by MyPy (using `py.typed` marker files). While generally backward compatible, custom build systems or highly specific `mypy` configurations might need adjustment.
Install
-
pip install boto3 mypy-boto3-efs
Imports
- EFSClient
from mypy_boto3_efs.client import EFSClient
- CreateFileSystemRequestRequestTypeDef
from mypy_boto3_efs.type_defs import CreateFileSystemRequestRequestTypeDef
Quickstart
import boto3
from mypy_boto3_efs.client import EFSClient
from mypy_boto3_efs.type_defs import CreateFileSystemRequestRequestTypeDef
import os
# Ensure boto3 can find credentials (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, or ~/.aws/credentials)
# This example does not explicitly set credentials, relying on default boto3 behavior.
def create_efs_filesystem(token: str) -> None:
client: EFSClient = boto3.client(
"efs",
region_name=os.environ.get('AWS_REGION', 'us-east-1')
)
request_params: CreateFileSystemRequestRequestTypeDef = {
"CreationToken": token,
"PerformanceMode": "generalPurpose",
"Encrypted": False # Set to True for encryption
}
try:
response = client.create_file_system(**request_params)
print(f"Created EFS File System with ID: {response['FileSystemId']}")
print(f"ARN: {response['FileSystemArn']}")
except client.exceptions.FileSystemAlreadyExists as e:
print(f"File system with token '{token}' already exists: {e}")
except Exception as e:
print(f"Error creating file system: {e}")
# Example usage (replace with a unique token for actual creation)
# create_efs_filesystem("my-unique-efs-token")
print("Run 'create_efs_filesystem("my-unique-efs-token")' to test")