mypy-boto3-ebs type stubs

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-ebs` with `boto3` to get type-hinted AWS EBS client interactions. The `TYPE_CHECKING` block ensures that type-only imports don't cause runtime overhead. Run `mypy <filename>.py` to verify type correctness.

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

view raw JSON →