Registry / type-stubs / mypy-boto3-ec2

mypy-boto3-ec2

JSON →
library1.42.85pypypiunverified

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.

type-stubsaws
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
musl
glibc
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
py 3.9
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()
Debug
Known footguns
breakingPython 3.8 support was removed for all `mypy-boto3-*` packages, including `mypy-boto3-ec2`, starting from version `8.12.0` of the builder. Projects on Python 3.8 will need to upgrade their Python version to 3.9+.
gotchaIt's crucial to install `mypy-boto3-ec2` (or any `mypy-boto3-*` package) with a version that matches your `boto3` installation as closely as possible. Mismatched versions can lead to incorrect type hints or `mypy` errors.
breakingFrom builder version `8.9.0`, TypeDef names for packed method arguments were shortened (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). Additionally, conflicting TypeDef `Extra` postfixes were moved (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`).
gotchaAWS service names can change or be deprecated (e.g., `sms-voice` was replaced by `pinpoint-sms-voice` for `mypy-boto3-*` packages in builder version `8.11.0`). While `ec2` is stable, be aware that you might need to update the specific `mypy-boto3-*` package if you work with other AWS services whose names evolve.
breakingBoto3 clients require an AWS region to be specified. If no region is explicitly configured in your environment or code, `botocore.exceptions.NoRegionError` will be raised.
gotchaWhen using `boto3` clients, including those with `mypy-boto3-*` type hints, it is mandatory to configure an AWS region. This error occurs if no region is specified via environment variables (e.g., `AWS_DEFAULT_REGION`), AWS config files, or directly in the client creation (e.g., `boto3.client('ec2', region_name='us-east-1')`).
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.

Agent activity
54 hits · last 30 days
petalbot
8
claudebot
8
bytedance
5
gptbot
4
ahrefsbot
4
amazonbot
4
chatgpt-user
1
Resources