mypy-boto3-pipes Type Annotations
mypy-boto3-pipes provides type annotations for the `boto3` EventBridgePipes service, ensuring compatibility with type checkers like Mypy, Pyright, and various IDEs. It is part of the `mypy-boto3` family of projects, generated by `mypy-boto3-builder`, and its version aligns with the corresponding `boto3` version. The library is actively maintained with frequent updates following `boto3` releases.
Warnings
- breaking Support for Python 3.8 was removed in `mypy-boto3-builder` version 8.12.0, which generates these stubs. Ensure your environment uses Python 3.9 or higher.
- breaking TypeDef names were shortened in `mypy-boto3-builder` 8.9.0 (e.g., `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef`). If you manually import TypeDefs, their names might have changed.
- gotcha This library provides only type stubs. You must install `boto3` (the actual AWS SDK) separately for your code to run. `mypy-boto3-pipes` provides no runtime functionality.
- gotcha The version of `mypy-boto3-pipes` should ideally match the major and minor version of your installed `boto3` library for full compatibility and accurate type hints.
- gotcha For production environments, it is recommended to wrap imports of `mypy-boto3` stubs within `if TYPE_CHECKING:` blocks to prevent them from becoming runtime dependencies.
- gotcha Users of PyCharm may experience slow performance or high CPU usage due to `Literal` overloads. Consider using `mypy-boto3-pipes-lite` or an external type checker like Mypy/Pyright.
Install
-
pip install mypy-boto3-pipes boto3 mypy
Imports
- PipesClient
from mypy_boto3_pipes.client import PipesClient
- EventBridgePipesServiceName
from mypy_boto3_pipes.literals import EventBridgePipesServiceName
- PipeStateTypeDef
from mypy_boto3_pipes.type_defs import PipeStateTypeDef
Quickstart
import boto3
import os
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from mypy_boto3_pipes.client import PipesClient
from mypy_boto3_pipes.type_defs import ListPipesResponseTypeDef
# Ensure boto3 is configured, e.g., via AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION
# For this example, we'll just create a client.
# In a real application, ensure credentials are set up (e.g., via environment variables or ~/.aws/credentials)
def get_pipes_client() -> 'PipesClient':
# The explicit type annotation here (PipesClient) enables type checking and autocompletion
client: PipesClient = boto3.client(
"pipes",
aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', 'DUMMY_KEY'),
aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', 'DUMMY_SECRET'),
region_name=os.environ.get('AWS_REGION', 'us-east-1')
)
return client
def list_eventbridge_pipes():
pipes_client = get_pipes_client()
try:
response: ListPipesResponseTypeDef = pipes_client.list_pipes(
MaxResults=5
)
print("Successfully listed pipes:")
for pipe in response.get('Pipes', []):
print(f" Pipe Name: {pipe.get('Name')}, State: {pipe.get('State')}")
except Exception as e:
print(f"Error listing pipes: {e}")
if __name__ == "__main__":
list_eventbridge_pipes()