mypy-boto3-ebs type stubs
mypy-boto3-ebs provides comprehensive type annotations for the AWS EBS service client, paginators, and waiters for `boto3`. It enhances development with static type checking, preventing common runtime errors related to incorrect API usage. The current version is 1.42.3, generated by `mypy-boto3-builder`, which frequently updates its stubs to match new `boto3` releases.
Warnings
- breaking Python 3.8 is no longer supported across all `mypy-boto3-*` packages. Ensure your project uses Python 3.9 or newer.
- breaking Internal `TypeDef` naming conventions changed, potentially shortening names for packed method arguments (e.g., `*RequestRequestTypeDef` to `*RequestTypeDef`). This impacts direct imports and usage of these `TypeDef` objects.
- gotcha `mypy-boto3-ebs` provides only type stubs. You must still install `boto3` to use the AWS SDK at runtime. Without `boto3`, your code will fail to execute.
- gotcha Type stubs are only useful if you are running a static type checker like `mypy`. Without `mypy` (or equivalent), these packages provide no runtime benefit and do not enforce type safety.
- gotcha The `mypy-boto3-*` ecosystem relies on `boto3` to match versions. While `mypy-boto3-ebs` tracks the `boto3` version, explicit version pinning of `boto3` and `mypy-boto3-ebs` is recommended to avoid type mismatches after `boto3` updates.
Install
-
pip install mypy-boto3-ebs boto3 mypy
Imports
- EBSClient
from mypy_boto3_ebs.client import EBSClient
- EBSWaiter
from mypy_boto3_ebs.waiter import EBSWaiter
- EBSPaginator
from mypy_boto3_ebs.paginator import EBSPaginator
- ListSnapshotsResultTypeDef
from mypy_boto3_ebs.type_defs import ListSnapshotsResultTypeDef
Quickstart
from typing import TYPE_CHECKING
import boto3
import os
# These imports are only for type checking, they don't affect runtime behavior.
if TYPE_CHECKING:
from mypy_boto3_ebs.client import EBSClient
from mypy_boto3_ebs.type_defs import ListSnapshotsResultTypeDef
# Runtime Boto3 client
# For real applications, configure credentials securely (e.g., AWS CLI, environment variables)
client = boto3.client(
"ebs",
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET'),
region_name=os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')
)
# Type hint the client for static analysis (optional but recommended)
ebs_client: EBSClient = client
# Use the client as usual. Type stubs provide autocompletion and error checking.
try:
response: ListSnapshotsResultTypeDef = ebs_client.list_snapshots()
print("EBS Snapshots found:", len(response.get('Snapshots', [])))
for snapshot in response.get('Snapshots', []):
print(f" - {snapshot.get('SnapshotId')}: {snapshot.get('Description')}")
except Exception as e:
print(f"Error listing snapshots: {e}")
# To verify type checking, save this code as example.py and run:
# mypy example.py