mypy-boto3-codepipeline: Type Annotations for boto3 CodePipeline

1.42.3 · active · verified Sat Apr 11

This library provides type annotations (stubs) for the `boto3` AWS CodePipeline client. It enables static type checking for `boto3` usage with tools like `mypy`, enhancing developer productivity and catching potential errors at compile time. Maintained by the `mypy-boto3-builder` project, it receives frequent updates to align with new `boto3` releases and `botocore` service definitions.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `mypy-boto3-codepipeline` to add static type checking to your `boto3` CodePipeline client interactions. The `TYPE_CHECKING` guard ensures that the stub imports are only processed by type checkers like `mypy` and are not loaded during runtime, improving application startup performance.

import boto3
from typing import TYPE_CHECKING, List, Dict, Any

# Guard type imports for runtime efficiency
if TYPE_CHECKING:
    from mypy_boto3_codepipeline.client import CodePipelineClient
    from mypy_boto3_codepipeline.type_defs import ListPipelinesOutputTypeDef
    
def get_codepipeline_pipelines() -> List[str]:
    # The actual runtime client from boto3
    client: CodePipelineClient = boto3.client("codepipeline")

    # The type checker knows the methods available on 'client'
    response: ListPipelinesOutputTypeDef = client.list_pipelines()
    
    pipeline_names = [
        p['name'] for p in response.get("pipelines", [])
        if 'name' in p and isinstance(p['name'], str)
    ]
    print(f"CodePipeline Pipelines: {pipeline_names}")
    return pipeline_names

if __name__ == "__main__":
    # This example does not require specific credentials beyond default AWS configuration.
    # Ensure boto3 is configured (e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, 
    # or ~/.aws/credentials, or IAM roles).
    try:
        pipelines = get_codepipeline_pipelines()
    except Exception as e:
        print(f"Error fetching CodePipeline pipelines: {e}")
        print("Please ensure your AWS credentials and region are configured.")

view raw JSON →