Type Annotations for boto3 ComprehendMedical
mypy-boto3-comprehendmedical provides comprehensive type annotations (stubs) for the boto3 ComprehendMedical client. Generated by `mypy-boto3-builder`, this package enhances development with static type checking, improved IDE auto-completion, and early error detection for your AWS ComprehendMedical interactions. It closely tracks `boto3` releases, with the current version being 1.42.3, compatible with boto3 1.42.3 and generated by builder 8.12.0.
Warnings
- breaking Python 3.8 support was removed for `mypy-boto3-builder` version 8.12.0 and later, which generated this package version. Consequently, `mypy-boto3-comprehendmedical` 1.42.3 and newer versions require Python 3.9 or higher.
- breaking The `mypy-boto3-builder` (version 8.12.0+) migrated to PEP 561 compliant packages. This change might affect how some tools or older `mypy` versions discover and use the stubs if your `mypy` configuration is not up-to-date or if you relied on older stub discovery mechanisms (e.g., specific `MYPYPATH` configurations for non-installed stubs).
- gotcha This package provides type stubs, not the actual runtime implementation of `boto3`. You must install `boto3` separately for your code to function at runtime.
- gotcha The type hints provided by this library are only utilized by static type checkers (like `mypy`) and IDEs (like VSCode, PyCharm) for analysis and auto-completion. They do not enforce types at runtime.
- gotcha For accurate type checking, the version of `mypy-boto3-comprehendmedical` should ideally match the version of `boto3` you are using. Mismatched versions can lead to incorrect type hints or missing attributes if `boto3` introduces changes not yet reflected in the stubs.
Install
-
pip install mypy-boto3-comprehendmedical boto3 mypy
Imports
- ComprehendMedicalClient
from mypy_boto3_comprehendmedical.client import ComprehendMedicalClient
- DetectEntitiesV2ResponseTypeDef
from mypy_boto3_comprehendmedical.type_defs import DetectEntitiesV2ResponseTypeDef
Quickstart
import boto3
from typing import TYPE_CHECKING
from mypy_boto3_comprehendmedical.client import ComprehendMedicalClient
from mypy_boto3_comprehendmedical.type_defs import DetectEntitiesV2ResponseTypeDef
if TYPE_CHECKING:
client: ComprehendMedicalClient = boto3.client("comprehendmedical")
else:
client = boto3.client("comprehendmedical")
# Example usage with type-hinted client
def process_medical_text(text: str) -> DetectEntitiesV2ResponseTypeDef:
try:
response: DetectEntitiesV2ResponseTypeDef = client.detect_entities_v2(
Text=text
)
print(f"Detected entities: {len(response['Entities'])}")
return response
except client.exceptions.ClientError as e:
print(f"Error processing text: {e}")
raise
# Example call
medical_note = "Patient has a history of type 2 diabetes and hypertension."
if __name__ == "__main__":
# In a real application, you'd handle AWS credentials/region configuration
# or use boto3's default credential chain.
# For this example, ensure AWS credentials are configured (e.g., via environment variables or ~/.aws/credentials)
try:
result = process_medical_text(medical_note)
# Further processing of result, e.g., result['Entities'][0]['Text']
except Exception as e:
print(f"An error occurred during quickstart: {e}")