mypy-boto3-codeconnections
mypy-boto3-codeconnections provides type annotations for the `boto3` AWS CodeConnections service. It enables static type checking for `boto3` interactions, improving code readability, auto-completion in IDEs, and allowing early error detection for AWS API calls. This package is generated by `mypy-boto3-builder` version 8.12.0 and is frequently updated, typically in sync with `boto3` releases.
Warnings
- breaking As of `mypy-boto3-builder` 8.12.0 (which generates this stub package), support for Python 3.8 has been removed. Ensure your projects use Python 3.9 or newer.
- breaking The `mypy-boto3-builder` (which generates these stubs) migrated to PEP 561 packages in version 8.12.0. While this generally improves stub discovery, it might require updates to custom build processes or `mypy` configurations that relied on older stub distribution methods.
- gotcha This library provides *type stubs* for `boto3`, not the `boto3` library itself. You must install `boto3` separately (e.g., `pip install boto3`) for your code to run at runtime.
- gotcha Previous versions of `mypy-boto3-builder` (8.9.0) introduced breaking changes to TypeDef naming conventions (e.g., `CreateDistributionRequestRequestTypeDef` -> `CreateDistributionRequestTypeDef`). If upgrading from very old versions, check for such changes in generated type definitions.
- gotcha PyCharm users might experience slow performance or high CPU usage due to an issue with Literal overloads (PY-40997). For better performance in PyCharm, `boto3-stubs-lite` is recommended as an alternative.
Install
-
pip install mypy-boto3-codeconnections boto3
Imports
- CodeConnectionsClient
from mypy_boto3_codeconnections.client import CodeConnectionsClient
- ListConnectionsOutputTypeDef
from mypy_boto3_codeconnections.type_defs import ListConnectionsOutputTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING, cast
import os
if TYPE_CHECKING:
from mypy_boto3_codeconnections.client import CodeConnectionsClient
from mypy_boto3_codeconnections.type_defs import ListConnectionsOutputTypeDef
def get_codeconnections_client() -> "CodeConnectionsClient":
"""
Returns a type-hinted boto3 CodeConnections client.
"""
# In a real application, region_name might come from environment or config.
client = boto3.client("codeconnections", region_name=os.environ.get("AWS_REGION_NAME", "us-east-1"))
return cast("CodeConnectionsClient", client)
def list_all_connections():
"""
Lists all CodeConnections connections with type hints.
"""
client = get_codeconnections_client()
# In a live environment, this would be an actual API call:
# response: ListConnectionsOutputTypeDef = client.list_connections()
# For a runnable example, we use a dummy response matching the expected type.
response: "ListConnectionsOutputTypeDef" = {
"Connections": [
{
"ConnectionArn": "arn:aws:codeconnections:us-east-1:123456789012:connection/a1b2c3d4",
"ConnectionName": "my-github-connection",
"ProviderType": "GitHub",
"OwnerAccountId": "123456789012",
"ConnectionStatus": "AVAILABLE"
}
],
"NextToken": None
}
print("CodeConnections:")
for connection in response.get("Connections", []):
print(f" - Name: {connection['ConnectionName']}, ARN: {connection['ConnectionArn']}")
return response
if __name__ == '__main__':
# Set dummy environment variables for the example to run locally without actual AWS credentials.
# In a real scenario, boto3 would automatically pick these up or use IAM roles.
os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY')
os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET')
os.environ['AWS_REGION_NAME'] = os.environ.get('AWS_REGION_NAME', 'us-east-1')
list_all_connections()