{"id":2128,"library":"mypy-boto3-bedrock-runtime","title":"mypy-boto3-bedrock-runtime Type Annotations","description":"mypy-boto3-bedrock-runtime provides comprehensive type annotations for the `boto3` Bedrock Runtime service, version 1.42.82. Generated by `mypy-boto3-builder` (version 8.12.0), it enhances developer experience by offering static type checking, auto-completion, and error detection in IDEs like VSCode and PyCharm, and with type checkers like Mypy and Pyright. The library is actively maintained and frequently updated to synchronize with `boto3` releases and schema changes.","status":"active","version":"1.42.82","language":"en","source_language":"en","source_url":"https://github.com/youtype/mypy_boto3_builder","tags":["boto3","aws","bedrock","runtime","type-hints","mypy","stubs","static-analysis"],"install":[{"cmd":"pip install mypy-boto3-bedrock-runtime boto3","lang":"bash","label":"Install with pip"}],"dependencies":[{"reason":"Provides the AWS SDK for Python that these stubs type-check.","package":"boto3","optional":false},{"reason":"A static type checker that consumes these stubs.","package":"mypy","optional":true},{"reason":"Requires Python 3.9 or newer.","package":"python","optional":false}],"imports":[{"note":"Client types are provided by the `mypy-boto3` stub package, not directly by `boto3` or `botocore`.","wrong":"from boto3.client import BedrockRuntimeClient","symbol":"BedrockRuntimeClient","correct":"from mypy_boto3_bedrock_runtime import BedrockRuntimeClient"},{"note":"Paginator types are located in the `paginator` submodule.","symbol":"ListAsyncInvokesPaginator","correct":"from mypy_boto3_bedrock_runtime.paginator import ListAsyncInvokesPaginator"},{"note":"Literal types (e.g., specific string values) are in the `literals` submodule.","symbol":"AsyncInvokeStatusType","correct":"from mypy_boto3_bedrock_runtime.literals import AsyncInvokeStatusType"},{"note":"TypedDicts for API request/response structures are in the `type_defs` submodule.","symbol":"AppliedGuardrailDetailsTypeDef","correct":"from mypy_boto3_bedrock_runtime.type_defs import AppliedGuardrailDetailsTypeDef"}],"quickstart":{"code":"import boto3\nfrom typing import TYPE_CHECKING\nimport os\n\nif TYPE_CHECKING:\n    from mypy_boto3_bedrock_runtime import BedrockRuntimeClient\n    from mypy_boto3_bedrock_runtime.type_defs import InvokeModelResponseTypeDef\n    from mypy_boto3_bedrock_runtime.paginator import ListAsyncInvokesPaginator\n\ndef get_bedrock_runtime_client() -> \"BedrockRuntimeClient\":\n    \"\"\"Returns a typed BedrockRuntime client.\"\"\"\n    return boto3.client(\n        \"bedrock-runtime\",\n        region_name=os.environ.get('AWS_REGION', 'us-east-1'),\n        aws_access_key_id=os.environ.get('AWS_ACCESS_KEY_ID', ''),\n        aws_secret_access_key=os.environ.get('AWS_SECRET_ACCESS_KEY', ''),\n        aws_session_token=os.environ.get('AWS_SESSION_TOKEN', '')\n    )\n\ndef invoke_model_example():\n    client: BedrockRuntimeClient = get_bedrock_runtime_client()\n    # Example: Invoke a model (replace with actual model_id and body)\n    response: InvokeModelResponseTypeDef = client.invoke_model(\n        modelId=\"anthropic.claude-v2\",\n        contentType=\"application/json\",\n        accept=\"application/json\",\n        body='{\"prompt\": \"Human: Hello, how are you? Assistant:\", \"max_tokens_to_sample\": 200}'\n    )\n    print(f\"Model invocation response: {response['body'].read().decode('utf-8')}\")\n\ndef list_async_invokes_paginator_example():\n    client: BedrockRuntimeClient = get_bedrock_runtime_client()\n    paginator: ListAsyncInvokesPaginator = client.get_paginator(\"list_async_invokes\")\n    for page in paginator.paginate():\n        print(f\"Async invokes page: {page.get('asyncInvokes')}\")\n\nif __name__ == \"__main__\":\n    invoke_model_example()\n    list_async_invokes_paginator_example()","lang":"python","description":"This quickstart demonstrates how to obtain a type-annotated BedrockRuntime client using `mypy-boto3-bedrock-runtime`. It shows how to call a client method (`invoke_model`) and how to use a paginator (`list_async_invokes`), leveraging `TYPE_CHECKING` for conditional imports. Ensure `boto3` is installed and AWS credentials are configured in your environment or via standard AWS configuration methods."},"warnings":[{"fix":"Upgrade your Python environment to 3.9 or a later version.","message":"Starting with `mypy-boto3-builder` version 8.12.0, support for Python 3.8 has been removed. All generated packages, including `mypy-boto3-bedrock-runtime`, now require Python 3.9 or newer.","severity":"breaking","affected_versions":"mypy-boto3-builder >=8.12.0"},{"fix":"Review your TypeDef imports and usages, adjusting names according to the new conventions.","message":"Version 8.9.0 of `mypy-boto3-builder` introduced breaking changes in TypeDef naming conventions. Specifically, `RequestRequestTypeDef` suffixes were shortened to `RequestTypeDef`, and `Extra` postfixes were moved to the end of TypeDef names (e.g., `CreateDistributionExtraRequestTypeDef` became `CreateDistributionRequestExtraTypeDef`). While `mypy-boto3-bedrock-runtime` specific changes might be rare, these builder-wide changes affect how you reference TypeDefs across all `mypy-boto3` stubs.","severity":"breaking","affected_versions":"mypy-boto3-builder >=8.9.0"},{"fix":"Encapsulate `mypy-boto3-*` imports within `from typing import TYPE_CHECKING` and `if TYPE_CHECKING:` blocks.","message":"It is best practice to wrap type stub imports within an `if TYPE_CHECKING:` block. This ensures that the type stubs are only loaded during static analysis by tools like Mypy and Pyright, preventing them from becoming runtime dependencies in your production environment.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure that your `boto3` installation closely matches the version indicated in the `mypy-boto3-bedrock-runtime` package name (e.g., `mypy-boto3-bedrock-runtime==1.42.82` for `boto3==1.42.82`).","message":"The `mypy-boto3-bedrock-runtime` package is generated for a specific `boto3` version (1.42.82 in this case). Mismatching `boto3` runtime versions with the installed stub version can lead to incorrect type hints or unresolved attributes, as the API might have changed between `boto3` versions.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Add explicit type annotations when initializing `boto3` clients, paginators, and waiters, e.g., `client: BedrockRuntimeClient = boto3.client(\"bedrock-runtime\")`.","message":"While `mypy` can often infer types, explicitly annotating the return type of `boto3.client(\"bedrock-runtime\")` with `BedrockRuntimeClient` (and similarly for paginators and waiters) provides the most robust type checking and significantly improves auto-completion in IDEs like VSCode and PyCharm, especially for `boto3`'s dynamically generated clients.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}