Type Annotations for boto3 ComprehendMedical

1.42.3 · active · verified Sat Apr 11

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a type-hinted ComprehendMedical client and use one of its methods, `detect_entities_v2`. It uses `TYPE_CHECKING` for conditional imports, ensuring the stubs are only active during type checking.

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}")

view raw JSON →