mypy-boto3-textract
mypy-boto3-textract provides a complete set of type annotations for the boto3 Textract service. These stubs enable static type checking for boto3 client operations, improving code quality and developer experience by catching type-related errors at development time. It is generated by the mypy-boto3-builder project and typically releases new versions in sync with boto3 updates, currently at 1.42.3.
Warnings
- breaking Support for Python 3.8 was officially removed with `mypy-boto3-builder` version 8.12.0. Consequently, `mypy-boto3-textract` versions generated by this builder or newer will not support Python 3.8.
- breaking Type definition (TypeDef) names were shortened and modified in `mypy-boto3-builder` version 8.9.0. This caused changes like `CreateDistributionRequestRequestTypeDef` becoming `CreateDistributionRequestTypeDef`. Code directly importing or referencing these specific TypeDef names will break.
- gotcha Ensure your `boto3` runtime package version is compatible with `mypy-boto3-textract`. While `mypy-boto3-textract` specifies `boto3` as a dependency, explicitly managing `boto3` versions (e.g., `boto3>=1.42.0,<2.0.0`) can prevent unexpected type-checking or runtime errors if mismatches occur.
- gotcha All `mypy-boto3` packages, including `mypy-boto3-textract`, migrated to PEP 561 compliance (marked with `py.typed`) in `mypy-boto3-builder` version 8.12.0. While this is an improvement for type checkers, older build systems or custom tooling might require updates to properly handle this new package structure.
Install
-
pip install mypy-boto3-textract
Imports
- TextractClient
from mypy_boto3_textract.client import TextractClient
- AnalyzeDocumentResponseTypeDef
from mypy_boto3_textract.type_defs import AnalyzeDocumentResponseTypeDef
Quickstart
import boto3
from mypy_boto3_textract.client import TextractClient
from mypy_boto3_textract.type_defs import AnalyzeDocumentResponseTypeDef, DocumentTypeDef # Import for detailed typing
def get_typed_textract_client() -> TextractClient:
"""
Demonstrates how to obtain a type-hinted Textract client.
The actual boto3 client is created, and the `TextractClient` type stub
provides static analysis for its methods.
"""
# boto3 automatically handles authentication via environment variables
# (e.g., AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY) or other credential providers.
# No explicit os.environ.get is typically needed here for the stubs to function,
# as they primarily assist static analysis, not runtime credential fetching.
client: TextractClient = boto3.client("textract", region_name="us-east-1") # Specify region for a valid client
print(f"Successfully obtained a type-hinted Textract client: {type(client)}")
# You can now use 'client' with full type-hinting support
# For example, client.analyze_document(...)
return client
if __name__ == '__main__':
typed_client = get_typed_textract_client()
# At this point, `typed_client` has all the type hints for the Textract service,
# enabling static analysis in your IDE or with mypy.
# A live call (e.g., typed_client.analyze_document(...)) would require
# valid AWS credentials and appropriate permissions at runtime.