{"id":3301,"library":"types-aiobotocore-ec2","title":"Type Annotations for aiobotocore EC2","description":"This library provides comprehensive type annotations for the aiobotocore EC2 service (version 3.4.0), generated by `mypy-boto3-builder`. It enables static type checking with tools like MyPy and Pyright, offering improved developer experience for asynchronous AWS interactions. The project maintains an active release cadence, often aligning with `aiobotocore` and `botocore` updates.","status":"active","version":"3.4.0","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["aws","aiobotocore","ec2","types","mypy","typing","stubs","type-hinting"],"install":[{"cmd":"pip install types-aiobotocore-ec2","lang":"bash","label":"Install standalone package"},{"cmd":"pip install 'types-aiobotocore[ec2]'","lang":"bash","label":"Install as part of 'types-aiobotocore' umbrella package"}],"dependencies":[{"reason":"This package provides type stubs for aiobotocore. The runtime library is required for execution.","package":"aiobotocore","optional":false},{"reason":"While Python 3.9+ is required, aiobotocore itself lists typing-extensions as a dependency, and the builder ensures its version compatibility.","package":"typing-extensions","optional":false}],"imports":[{"symbol":"EC2Client","correct":"from types_aiobotocore_ec2.client import EC2Client"},{"symbol":"DescribeInstancesResultTypeDef","correct":"from types_aiobotocore_ec2.type_defs import DescribeInstancesResultTypeDef"},{"symbol":"EC2ServiceResource","correct":"from types_aiobotocore_ec2.service_resource import EC2ServiceResource"}],"quickstart":{"code":"import asyncio\nfrom aiobotocore.session import get_session\nfrom typing import TYPE_CHECKING\n\nif TYPE_CHECKING:\n    from types_aiobotocore_ec2.client import EC2Client\n    from types_aiobotocore_ec2.type_defs import DescribeInstancesResultTypeDef\n\nasync def describe_ec2_instances():\n    session = get_session()\n    async with session.create_client(\"ec2\") as client:\n        # Explicit type annotation for the client\n        client: \"EC2Client\" = client\n        response = await client.describe_instances()\n        \n        print(f\"Found {len(response['Reservations'])} reservations.\")\n        for reservation in response['Reservations']:\n            for instance in reservation['Instances']:\n                print(f\"  Instance ID: {instance['InstanceId']}, State: {instance['State']['Name']}\")\n        \n        # Example of using a TypeDef for a dictionary structure\n        example_type_def: \"DescribeInstancesResultTypeDef\" = response\n        print(f\"Example TypeDef Reservations key: {example_type_def['Reservations'][0]['ReservationId']}\")\n\nif __name__ == \"__main__\":\n    asyncio.run(describe_ec2_instances())\n","lang":"python","description":"This example demonstrates how to set up an `aiobotocore` client for EC2 and apply type annotations using `types-aiobotocore-ec2`. It explicitly types the client and shows how to leverage TypeDefs for response objects, enabling better static analysis and IDE autocompletion for asynchronous AWS calls."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or newer.","message":"Support for Python 3.8 has been removed in `mypy-boto3-builder` version 8.12.0 and subsequent generated packages. Users on Python 3.8 must either upgrade Python or use an older version of `types-aiobotocore-ec2`.","severity":"breaking","affected_versions":">=3.4.0 (for types-aiobotocore-ec2), >=8.12.0 (for mypy-boto3-builder)"},{"fix":"Review your type hints and update TypeDef names according to the latest generated types if you experience `NameError` or type resolution issues.","message":"Generated TypeDef naming conventions may have changed in `mypy-boto3-builder` version 8.9.0. For instance, `CreateDistributionRequestRequestTypeDef` might become `CreateDistributionRequestTypeDef`. Code relying on specific TypeDef names may break.","severity":"breaking","affected_versions":">=3.x.x (for types-aiobotocore-ec2), >=8.9.0 (for mypy-boto3-builder)"},{"fix":"Ensure both `aiobotocore` and `types-aiobotocore-ec2` are installed in your environment.","message":"Installing `types-aiobotocore-ec2` only provides type annotations. For actual runtime execution, you must also install the `aiobotocore` library itself (`pip install aiobotocore`).","severity":"gotcha","affected_versions":"all"},{"fix":"Add explicit type annotations for clients, resources, paginators, and waiters imported from `types_aiobotocore_ec2`.","message":"When using standalone service packages like `types-aiobotocore-ec2` or `types-aiobotocore-lite`, explicit type annotations (e.g., `client: EC2Client`) are often required for full type checking and IDE support. The main `types-aiobotocore` package with overloads can sometimes infer types implicitly.","severity":"gotcha","affected_versions":"all"},{"fix":"Consider using the `-lite` version of the stubs (`types-aiobotocore-lite-ec2` if available) or disable PyCharm's internal type checker and rely on external tools like MyPy or Pyright instead.","message":"PyCharm users might experience slow performance or high CPU usage due to the large number of `Literal` overloads in these stub packages (related to PyCharm issue PY-40997).","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}