Type annotations for aiobotocore BedrockRuntime
Type annotations for `aiobotocore` BedrockRuntime service. This library provides static type checking for `aiobotocore` clients, resources, paginators, and service-specific `TypeDefs` and `Literals` for Amazon Bedrock Runtime. It is generated by `mypy-boto3-builder` and aims to be compatible with various IDEs and type checkers like mypy and pyright. The current version is 3.4.0 and it releases in sync with `aiobotocore` updates.
Warnings
- breaking Support for Python 3.8 has been removed. Users must upgrade to Python 3.9 or newer.
- breaking TypeDef names for method arguments and conflicting names may have changed to be shorter or use different postfixes (e.g., `RequestRequestTypeDef` -> `RequestTypeDef`, `ExtraRequestTypeDef` -> `RequestExtraTypeDef`). This can break existing explicit type annotations.
- gotcha When using PyCharm, slow performance or high CPU usage might occur due to how it handles Literal overloads in type stubs. It's recommended to either use an external type checker like mypy/pyright or consider the '-lite' version of types-aiobotocore if available for less strict type checking in the IDE.
- gotcha Pylint might report false positives about undefined variables when using type stubs with the `TYPE_CHECKING` flag. To resolve this, you might need to configure Pylint or explicitly set types to `object` in non-`TYPE_CHECKING` mode.
- gotcha This package provides *only* type annotations. The `aiobotocore` library itself (the runtime dependency) must be installed separately for your code to function.
Install
-
pip install types-aiobotocore-bedrock-runtime aiobotocore -
pip install 'types-aiobotocore[bedrock-runtime]' aiobotocore
Imports
- BedrockRuntimeClient
from types_aiobotocore_bedrock_runtime.client import BedrockRuntimeClient
- InvokeModelResponseTypeDef
from types_aiobotocore_bedrock_runtime.type_defs import InvokeModelResponseTypeDef
- AsyncInvokeStatusType
from types_aiobotocore_bedrock_runtime.literals import AsyncInvokeStatusType
Quickstart
import asyncio
from typing import TYPE_CHECKING
import aiobotocore.session
if TYPE_CHECKING:
from types_aiobotocore_bedrock_runtime.client import BedrockRuntimeClient
from types_aiobotocore_bedrock_runtime.type_defs import InvokeModelResponseTypeDef
async def main():
session = aiobotocore.session.get_session()
async with session.create_client("bedrock-runtime") as client:
client: BedrockRuntimeClient # Explicit type hint (optional, but good practice)
response: InvokeModelResponseTypeDef = await client.invoke_model(
modelId="anthropic.claude-3-sonnet-20240229-v1:0",
contentType="application/json",
accept="application/json",
body=b'{"prompt": "Human: Hello, world!\nAssistant:"}'
)
async with response["body"] as stream:
payload = stream.iter_bytes()
async for chunk in payload:
print(chunk.decode())
if __name__ == "__main__":
asyncio.run(main())