Registry /
type-stubs / mypy-boto3-ec2-instance-connect
Install & Compatibility
Where this runs
tested against v1.43.0 · 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
muslpy 3.10–3.910 runs
installs and imports cleanly · install 0.0s · import 0.010s · 198.8MB
glibcpy 3.10–3.910 runs
installs and imports cleanly · install 3.8s · import 0.006s · 267MB
232MB installed
● package 232MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
EC2InstanceConnectClient
✓ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_ec2_instance_connect.client import EC2InstanceConnectClient
Client type definitions are typically imported conditionally within a TYPE_CHECKING block to avoid runtime dependencies on stub packages.
SendSSHPublicKeyRequestRequestTypeDef
✓ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_ec2_instance_connect.type_defs import SendSSHPublicKeyRequestRequestTypeDef
Type definitions for service request parameters are imported from the `type_defs` module, usually within a TYPE_CHECKING block.
SendSSHPublicKeyResponseTypeDef
✓ from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_ec2_instance_connect.type_defs import SendSSHPublicKeyResponseTypeDef
Type definitions for service response objects are imported from the `type_defs` module, usually within a TYPE_CHECKING block.
This quickstart demonstrates how to initialize a `boto3` EC2InstanceConnect client and leverage `mypy-boto3-ec2-instance-connect` for type-hinting. The client creation relies on `boto3`'s standard credential chain (e.g., environment variables, `~/.aws/credentials`). Mypy will validate the types of the client object and any request dictionaries at static analysis time, enhancing code reliability.
import os
from typing import TYPE_CHECKING
import boto3
# Conditional import for type checking only
if TYPE_CHECKING:
from mypy_boto3_ec2_instance_connect.client import EC2InstanceConnectClient
from mypy_boto3_ec2_instance_connect.type_defs import (
SendSSHPublicKeyRequestRequestTypeDef,
SendSSHPublicKeyResponseTypeDef
)
def get_ec2_instance_connect_client() -> "EC2InstanceConnectClient":
"""
Returns a type-hinted EC2InstanceConnect client.
This function demonstrates how to obtain a client that mypy can type-check.
boto3 client creation will implicitly use AWS credentials from environment variables
(e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) or configuration files.
"""
# Explicitly retrieve AWS region to ensure it's set, for example.
aws_region = os.environ.get("AWS_REGION", "us-east-1")
# The returned client will be typed as EC2InstanceConnectClient by mypy
# but at runtime it's a botocore.client.EC2InstanceConnect
client: "EC2InstanceConnectClient" = boto3.client("ec2-instance-connect", region_name=aws_region)
return client
if __name__ == "__main__":
print("Attempting to get an EC2InstanceConnect client...")
try:
typed_client = get_ec2_instance_connect_client()
print(f"Successfully obtained client (runtime type: {type(typed_client)}).")
print("Note: If AWS credentials are not configured, subsequent API calls will fail.")
# Example of a type-checked dictionary for an API call
# mypy will validate the structure and types of this dictionary
sample_request: "SendSSHPublicKeyRequestRequestTypeDef" = {
"InstanceId": "i-1234567890abcdef0", # Placeholder for an actual EC2 instance ID
"InstanceOSUser": "ec2-user", # Placeholder for the OS user
"SSHPublicKey": "ssh-rsa AAAAB3NzaC...", # Placeholder for a valid public key
"AvailabilityZone": "us-east-1a" # Placeholder for the instance's AZ
}
print(f"\nExample type-checked request parameters:\n{sample_request}")
# To make an actual API call, uncomment the following.
# This will require valid AWS credentials and permissions.
# response: SendSSHPublicKeyResponseTypeDef = typed_client.send_ssh_public_key(**sample_request)
# print(f"\nAPI Response: {response}")
except Exception as e:
print(f"Error: Could not initialize client or access AWS: {e}")
print("Please ensure boto3 is installed and AWS credentials (e.g., via environment variables like AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION or ~/.aws/credentials) are configured correctly.")
Debug
Known issues
breakingStarting with `mypy-boto3-builder` version 8.12.0 (which generates this stub package), Python 3.8 is no longer supported. The minimum required Python version is now 3.9.fixUpgrade your Python environment to 3.9 or newer.
affects: mypy-boto3-builder >= 8.12.0, mypy-boto3-ec2-instance-connect >= 1.42.0
breakingIn `mypy-boto3-builder` 8.9.0, there were breaking changes to TypeDef naming conventions. Type definitions for packed method arguments now use shorter names (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`), and conflicting TypeDef `Extra` postfixes were moved to the end.fixReview and update your code to reflect the new TypeDef names, consulting the specific service's `type_defs.pyi` file if you encounter `NameError` during type checking.
affects: mypy-boto3-builder >= 8.9.0, mypy-boto3-ec2-instance-connect >= 1.41.x
gotchaThis package provides *only* type stubs. It does not include the `boto3` library itself. You must install `boto3` separately for your code to run.fixEnsure `boto3` is installed in your environment: `pip install boto3`.
affects: All versions
gotchaThe primary utility of `mypy-boto3-ec2-instance-connect` is for static type checking. Imports from this package (e.g., `from mypy_boto3_ec2_instance_connect.client import EC2InstanceConnectClient`) should ideally be placed within an `if TYPE_CHECKING:` block to prevent runtime dependencies and potential import errors if the stub package is not present at runtime.fixWrap type-stub imports with `from typing import TYPE_CHECKING` and `if TYPE_CHECKING:`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'mypy_boto3_ec2_instance_connect'
This error occurs because the `mypy-boto3-ec2-instance-connect` package, which provides type annotations for the `boto3` EC2InstanceConnect client, has not been installed in your Python environment.
fixInstall the package using pip: `pip install mypy-boto3-ec2-instance-connect`
error: Skipping analyzing 'boto3': found module but no type hints or library stubs
Mypy cannot find the necessary type stub files for the `boto3` library, including the `ec2-instance-connect` service, preventing it from performing static type checking. This usually means `mypy-boto3` or `boto3-stubs` is either not installed, or mypy is not correctly configured to find the installed stubs.
fixEnsure `mypy` and the specific stub package (`mypy-boto3-ec2-instance-connect` or `boto3-stubs[ec2-instance-connect]`) are installed in the same environment and that `mypy` is running against that environment. If using a virtual environment, activate it before running mypy. `pip install mypy 'boto3-stubs[ec2-instance-connect]'`
AttributeError: module 'botocore.client' has no attribute 'EC2InstanceConnect'
This error occurs when attempting to import or reference the `EC2InstanceConnectClient` type directly from `botocore.client` or an incorrect location, instead of importing it from the `mypy_boto3_ec2_instance_connect` stub package.
fixImport the client type from the correct `mypy_boto3_ec2_instance_connect` package, typically within a `TYPE_CHECKING` block to avoid runtime dependency: `from typing import TYPE_CHECKING
import boto3
if TYPE_CHECKING:
from mypy_boto3_ec2_instance_connect.client import EC2InstanceConnectClient
def get_client() -> EC2InstanceConnectClient:
return boto3.client('ec2-instance-connect')` mypy error: Incompatible types in assignment (expression has type "str", variable has type "ListInstancesResponseTypeDef")
This type checking error happens when you assign a value of an incorrect type (e.g., a simple string or a generic dictionary) to a variable that is explicitly type-hinted with a specific `mypy-boto3` `TypedDict` type definition for a Boto3 response. The `mypy-boto3` stubs provide precise `TypedDict` definitions for API responses to enable detailed type checking.
fixEnsure that the data structure you are assigning matches the `TypedDict` definition provided by `mypy-boto3`. You might need to import the specific `TypeDef` from `mypy_boto3_ec2_instance_connect.type_defs` and use it correctly, or construct your dictionary to conform to that `TypedDict`. Example (hypothetical, replace with actual response type): `from typing import TYPE_CHECKING
import boto3
if TYPE_CHECKING:
from mypy_boto3_ec2_instance_connect.client import EC2InstanceConnectClient
from mypy_boto3_ec2_instance_connect.type_defs import SendSSHPublicKeyResponseTypeDef
def send_key(client: EC2InstanceConnectClient) -> SendSSHPublicKeyResponseTypeDef:
response = client.send_ssh_public_key(...)
# mypy will check if 'response' structure matches SendSSHPublicKeyResponseTypeDef
return response` Upgrade
Version history
1.43.0latest on PyPI · released Apr 29, 2026
Audit
Dependencies
boto3requiredRuntime dependency for the AWS SDK client that these stubs type-check.
mypyrequiredRequired to perform type-checking; these packages provide the type definitions for it.