mypy-boto3-codestar-connections

1.42.3 · active · verified Sat Apr 11

mypy-boto3-codestar-connections provides type annotations for the boto3 CodeStar Connections service. It is part of the mypy-boto3 project, which generates a full set of type stubs for boto3 services to enhance static analysis with tools like Mypy. The project releases frequently, keeping pace with boto3 updates and Python ecosystem changes, and is currently at version 1.42.3.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-codestar-connections` to add type hints to your boto3 client. The `TYPE_CHECKING` block ensures that your IDE and Mypy can correctly infer the types for `client`, while the runtime code remains unaffected. It also includes placeholder AWS environment variables to satisfy initial Boto3 configuration checks, although valid credentials are required for successful API calls.

import boto3
from mypy_boto3_codestar_connections.client import CodeStarConnectionsClient
from typing import TYPE_CHECKING
import os

# Ensure boto3 is installed: pip install boto3 mypy-boto3-codestar-connections

# Provide dummy AWS credentials for the quickstart to pass basic boto3 checks.
# In a real application, boto3 will pick up credentials from env vars,
# ~/.aws/credentials, or IAM roles.
# These are placeholder values and will likely result in an 'InvalidClientTokenId'
# or 'AccessDenied' error if used without proper configuration.
# It's intended to demonstrate type-checking and basic client interaction.
os.environ['AWS_ACCESS_KEY_ID'] = os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY_ID')
os.environ['AWS_SECRET_ACCESS_KEY'] = os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET_ACCESS_KEY')
os.environ['AWS_DEFAULT_REGION'] = os.environ.get('AWS_DEFAULT_REGION', 'us-east-1')

# Use TYPE_CHECKING for type hints that are only relevant for static analysis
if TYPE_CHECKING:
    client: CodeStarConnectionsClient = boto3.client("codestar-connections")
else:
    client = boto3.client("codestar-connections")

try:
    # Example: List up to 1 CodeStar Connections
    print("Attempting to list CodeStar Connections...")
    response = client.list_connections(MaxResults=1)
    print("Successfully listed CodeStar Connections (if configured and permissions allow):")
    for conn in response.get("Connections", []):
        print(f"  Connection ARN: {conn.get('ConnectionArn')}")

except client.exceptions.CodeStarConnectionsException as e:
    print(f"AWS CodeStar Connections error: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →