Type Annotations for aiobotocore Textract

3.4.0 · active · verified Thu Apr 16

This library provides static type annotations for the `aiobotocore` Textract service client, enhancing code reliability through static type checking with tools like MyPy and Pyright. It is currently at version 3.4.0 and is generated by `mypy-boto3-builder 8.12.0`, receiving frequent updates in sync with new `aiobotocore` releases and builder improvements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize an `aiobotocore` Textract client and use it with type annotations provided by `types-aiobotocore-textract`. The example calls `analyze_document` with dummy S3 object details. For a successful run, replace `dummy_s3_bucket` and `dummy_s3_key` with actual values pointing to a document in an S3 bucket accessible by your AWS credentials.

import asyncio
from aiobotocore.session import get_session
from types_aiobotocore_textract.client import TextractClient

async def analyze_document_typed(s3_bucket: str, s3_key: str):
    session = get_session()
    async with session.create_client("textract") as client:  # type: TextractClient
        print(f"Client type: {type(client)}")
        try:
            response = await client.analyze_document(
                Document={
                    'S3Object': {
                        'Bucket': s3_bucket,
                        'Name': s3_key
                    }
                },
                FeatureTypes=['FORMS', 'TABLES']
            )
            print("Document analysis successful.")
            # Example of accessing a typed response
            document_metadata = response.get('DocumentMetadata')
            if document_metadata:
                print(f"Pages: {document_metadata.get('Pages')}")
        except client.ValidationException as e:
            print(f"Validation error: {e}")
        except Exception as e:
            print(f"An unexpected error occurred: {e}")

if __name__ == "__main__":
    # Replace with your S3 bucket and key for a document (e.g., PDF, PNG, JPG)
    # This example requires an actual S3 object for Textract to process.
    # For local testing without a real S3 object, Textract might raise an InvalidS3ObjectException or similar.
    dummy_s3_bucket = "your-s3-bucket"
    dummy_s3_key = "path/to/your/document.pdf"
    # You can use a dummy value if you only want to test type checking without actual execution
    # or ensure a real, accessible S3 object is configured for Textract.
    asyncio.run(analyze_document_typed(dummy_s3_bucket, dummy_s3_key))

view raw JSON →