mypy-boto3-bedrock-agent
mypy-boto3-bedrock-agent provides type annotations (stubs) for the `boto3` Bedrock Agent service, enhancing static type checking with tools like Mypy. It is part of the `mypy-boto3` ecosystem, which generates stubs for all `boto3` services. The library follows the `boto3` release cycle closely, with frequent updates to ensure compatibility with the latest AWS SDK features and API changes. Current version is 1.42.83.
Warnings
- breaking Support for Python 3.8 has been removed. Projects using `mypy-boto3-bedrock-agent` (and other `mypy-boto3` generated stubs) must use Python 3.9 or newer.
- breaking TypeDef naming conventions were changed in `mypy-boto3-builder`, potentially affecting direct references to generated TypeDefs. For example, `CreateDistributionRequestRequestTypeDef` became `CreateDistributionRequestTypeDef` and `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`.
- gotcha This package provides *only* type annotations (stubs). `boto3` itself must be installed and available at runtime for your application to function correctly.
- gotcha Installing `mypy-boto3-bedrock-agent` only provides stubs for the `bedrock-agent` service. If you use other `boto3` services (e.g., S3, EC2), you will need to install their respective `mypy-boto3-*` packages, or install the overarching `boto3-stubs` package for full coverage.
Install
-
pip install mypy-boto3-bedrock-agent boto3
Imports
- BedrockAgentClient
from mypy_boto3_bedrock_agent import BedrockAgentClient
- BedrockAgentClient
from mypy_boto3_bedrock_agent.client import BedrockAgentClient
Quickstart
import os
import boto3
from mypy_boto3_bedrock_agent import BedrockAgentClient
from botocore.exceptions import ClientError
# Ensure boto3 is installed and configured (e.g., via AWS environment variables
# AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION, or IAM roles).
# For local testing, ensure these are set or provide dummy values.
# Type hint the client to enable static analysis by Mypy
# region_name is typically required for Bedrock services.
client: BedrockAgentClient = boto3.client(
"bedrock-agent",
region_name=os.environ.get("AWS_REGION", "us-east-1")
)
try:
# Example operation: List existing agents
print("Attempting to list Bedrock Agents...")
response = client.list_agents(maxResults=5)
agents = response.get("agentSummaries", [])
if agents:
print("Successfully listed agents:")
for agent_summary in agents:
print(f" - Agent ID: {agent_summary['agentId']}, Name: {agent_summary['agentName']}")
else:
print("No Bedrock agents found in this region.")
except ClientError as e:
error_code = e.response.get("Error", {}).get("Code")
error_message = e.response.get("Error", {}).get("Message")
if error_code == "AccessDeniedException":
print(f"Access Denied: You might not have permissions to list agents. Error: {error_message}")
else:
print(f"An AWS Client Error occurred: {error_code} - {error_message}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
# Mypy will now correctly type-check method calls on `client`
# and the structure of `response` based on the AWS API definition.