mypy-boto3-ec2 provides type annotations for the boto3 EC2 service. It ensures that your boto3 client calls for EC2 are type-checked by tools like MyPy, catching potential errors at development time. The current version is 1.42.85, closely following boto3/botocore releases, with frequent updates tied to AWS API changes.
Install & Compatibility
Where this runs
tested against v1.43.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
py 3.10
8/10 runs
8/10 runs
py 3.11
8/10 runs
8/10 runs
py 3.12
8/10 runs
8/10 runs
py 3.13
8/10 runs
8/10 runs
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
from mypy_boto3_ec2 import EC2Client
This example demonstrates how to use `mypy-boto3-ec2` to type-hint an EC2 client and process its responses with type-safe accessors. It lists all EC2 instances in the default region.
import boto3
from mypy_boto3_ec2.client import EC2Client
from mypy_boto3_ec2.type_defs import InstanceTypeDef, ReservationTypeDef
def list_ec2_instances() -> None:
# Type-hint the boto3 client for EC2
ec2_client: EC2Client = boto3.client('ec2')
print('Describing EC2 instances...')
response = ec2_client.describe_instances()
# Use type definitions for better type checking on the response
for reservation in response.get('Reservations', []):
reservation_typed: ReservationTypeDef = reservation
for instance in reservation_typed.get('Instances', []):
instance_typed: InstanceTypeDef = instance
instance_id = instance_typed.get('InstanceId', 'N/A')
instance_type = instance_typed.get('InstanceType', 'N/A')
state = instance_typed.get('State', {}).get('Name', 'N/A')
print(f' Instance ID: {instance_id}, Type: {instance_type}, State: {state}')
if __name__ == '__main__':
# This quickstart assumes AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
list_ec2_instances()
Upgrade
Version history
Breaking-change detection hasn't run for this library yet.
Audit
Security & dependencies
CVE tracking and dependency tree are planned for a later release.