mypy-boto3-codepipeline: Type Annotations for boto3 CodePipeline
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
- breaking Python 3.8 support was removed and packages migrated to PEP 561.
- gotcha This package provides *only* type annotations (stubs) for boto3.
- gotcha For optimal type checking, align `mypy-boto3-codepipeline` with your `boto3` runtime version.
- gotcha Use `if TYPE_CHECKING:` guards for stub imports to avoid runtime overhead.
Install
-
pip install mypy-boto3-codepipeline -
pip install boto3 mypy
Imports
- CodePipelineClient
from mypy_boto3_codepipeline.client import CodePipelineClient
- ListPipelinesOutputTypeDef
from mypy_boto3_codepipeline.type_defs import ListPipelinesOutputTypeDef
Quickstart
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.")