Amazon Textract

2023/10/12 - Amazon Textract - 12 new2 updated api methods

Changes  This release adds 9 new APIs for adapter and adapter version management, 3 new APIs for tagging, and updates AnalyzeDocument and StartDocumentAnalysis API parameters for using adapters.

DeleteAdapterVersion (new) Link ¶

Deletes an Amazon Textract adapter version. Requires that you specify both an AdapterId and a AdapterVersion. Deletes the adapter version specified by the AdapterId and the AdapterVersion.

See also: AWS API Documentation

Request Syntax

client.delete_adapter_version(
    AdapterId='string',
    AdapterVersion='string'
)
type AdapterId:

string

param AdapterId:

[REQUIRED]

A string containing a unique ID for the adapter version that will be deleted.

type AdapterVersion:

string

param AdapterVersion:

[REQUIRED]

Specifies the adapter version to be deleted.

rtype:

dict

returns:

Response Syntax

{}

Response Structure

  • (dict) --

GetAdapterVersion (new) Link ¶

Gets configuration information for the specified adapter version, including: AdapterId, AdapterVersion, FeatureTypes, Status, StatusMessage, DatasetConfig, KMSKeyId, OutputConfig, Tags and EvaluationMetrics.

See also: AWS API Documentation

Request Syntax

client.get_adapter_version(
    AdapterId='string',
    AdapterVersion='string'
)
type AdapterId:

string

param AdapterId:

[REQUIRED]

A string specifying a unique ID for the adapter version you want to retrieve information for.

type AdapterVersion:

string

param AdapterVersion:

[REQUIRED]

A string specifying the adapter version you want to retrieve information for.

rtype:

dict

returns:

Response Syntax

{
    'AdapterId': 'string',
    'AdapterVersion': 'string',
    'CreationTime': datetime(2015, 1, 1),
    'FeatureTypes': [
        'TABLES'|'FORMS'|'QUERIES'|'SIGNATURES'|'LAYOUT',
    ],
    'Status': 'ACTIVE'|'AT_RISK'|'DEPRECATED'|'CREATION_ERROR'|'CREATION_IN_PROGRESS',
    'StatusMessage': 'string',
    'DatasetConfig': {
        'ManifestS3Object': {
            'Bucket': 'string',
            'Name': 'string',
            'Version': 'string'
        }
    },
    'KMSKeyId': 'string',
    'OutputConfig': {
        'S3Bucket': 'string',
        'S3Prefix': 'string'
    },
    'EvaluationMetrics': [
        {
            'Baseline': {
                'F1Score': ...,
                'Precision': ...,
                'Recall': ...
            },
            'AdapterVersion': {
                'F1Score': ...,
                'Precision': ...,
                'Recall': ...
            },
            'FeatureType': 'TABLES'|'FORMS'|'QUERIES'|'SIGNATURES'|'LAYOUT'
        },
    ],
    'Tags': {
        'string': 'string'
    }
}

Response Structure

  • (dict) --

    • AdapterId (string) --

      A string containing a unique ID for the adapter version being retrieved.

    • AdapterVersion (string) --

      A string containing the adapter version that has been retrieved.

    • CreationTime (datetime) --

      The time that the adapter version was created.

    • FeatureTypes (list) --

      List of the targeted feature types for the requested adapter version.

      • (string) --

    • Status (string) --

      The status of the adapter version that has been requested.

    • StatusMessage (string) --

      A message that describes the status of the requested adapter version.

    • DatasetConfig (dict) --

      Specifies a dataset used to train a new adapter version. Takes a ManifestS3Objec as the value.

      • ManifestS3Object (dict) --

        The S3 bucket name and file name that identifies the document.

        The AWS Region for the S3 bucket that contains the document must match the Region that you use for Amazon Textract operations.

        For Amazon Textract to process a file in an S3 bucket, the user must have permission to access the S3 bucket and file.

        • Bucket (string) --

          The name of the S3 bucket. Note that the # character is not valid in the file name.

        • Name (string) --

          The file name of the input document. Synchronous operations can use image files that are in JPEG or PNG format. Asynchronous operations also support PDF and TIFF format files.

        • Version (string) --

          If the bucket has versioning enabled, you can specify the object version.

    • KMSKeyId (string) --

      The identifier for your AWS Key Management Service key (AWS KMS key). Used to encrypt your documents.

    • OutputConfig (dict) --

      Sets whether or not your output will go to a user created bucket. Used to set the name of the bucket, and the prefix on the output file.

      OutputConfig is an optional parameter which lets you adjust where your output will be placed. By default, Amazon Textract will store the results internally and can only be accessed by the Get API operations. With OutputConfig enabled, you can set the name of the bucket the output will be sent to the file prefix of the results where you can download your results. Additionally, you can set the KMSKeyID parameter to a customer master key (CMK) to encrypt your output. Without this parameter set Amazon Textract will encrypt server-side using the AWS managed CMK for Amazon S3.

      Decryption of Customer Content is necessary for processing of the documents by Amazon Textract. If your account is opted out under an AI services opt out policy then all unencrypted Customer Content is immediately and permanently deleted after the Customer Content has been processed by the service. No copy of of the output is retained by Amazon Textract. For information about how to opt out, see Managing AI services opt-out policy.

      For more information on data privacy, see the Data Privacy FAQ.

      • S3Bucket (string) --

        The name of the bucket your output will go to.

      • S3Prefix (string) --

        The prefix of the object key that the output will be saved to. When not enabled, the prefix will be “textract_output".

    • EvaluationMetrics (list) --

      The evaluation metrics (F1 score, Precision, and Recall) for the requested version, grouped by baseline metrics and adapter version.

      • (dict) --

        Contains information on the metrics used to evalute the peformance of a given adapter version. Includes data for baseline model performance and individual adapter version perfromance.

        • Baseline (dict) --

          The F1 score, precision, and recall metrics for the baseline model.

          • F1Score (float) --

            The F1 score for an adapter version.

          • Precision (float) --

            The Precision score for an adapter version.

          • Recall (float) --

            The Recall score for an adapter version.

        • AdapterVersion (dict) --

          The F1 score, precision, and recall metrics for the baseline model.

          • F1Score (float) --

            The F1 score for an adapter version.

          • Precision (float) --

            The Precision score for an adapter version.

          • Recall (float) --

            The Recall score for an adapter version.

        • FeatureType (string) --

          Indicates the feature type being analyzed by a given adapter version.

    • Tags (dict) --

      A set of tags (key-value pairs) that are associated with the adapter version.

      • (string) --

        • (string) --

TagResource (new) Link ¶

Adds one or more tags to the specified resource.

See also: AWS API Documentation

Request Syntax

client.tag_resource(
    ResourceARN='string',
    Tags={
        'string': 'string'
    }
)
type ResourceARN:

string

param ResourceARN:

[REQUIRED]

The Amazon Resource Name (ARN) that specifies the resource to be tagged.

type Tags:

dict

param Tags:

[REQUIRED]

A set of tags (key-value pairs) that you want to assign to the resource.

  • (string) --

    • (string) --

rtype:

dict

returns:

Response Syntax

{}

Response Structure

  • (dict) --

ListTagsForResource (new) Link ¶

Lists all tags for an Amazon Textract resource.

See also: AWS API Documentation

Request Syntax

client.list_tags_for_resource(
    ResourceARN='string'
)
type ResourceARN:

string

param ResourceARN:

[REQUIRED]

The Amazon Resource Name (ARN) that specifies the resource to list tags for.

rtype:

dict

returns:

Response Syntax

{
    'Tags': {
        'string': 'string'
    }
}

Response Structure

  • (dict) --

    • Tags (dict) --

      A set of tags (key-value pairs) that are part of the requested resource.

      • (string) --

        • (string) --

ListAdapterVersions (new) Link ¶

List all version of an adapter that meet the specified filtration criteria.

See also: AWS API Documentation

Request Syntax

client.list_adapter_versions(
    AdapterId='string',
    AfterCreationTime=datetime(2015, 1, 1),
    BeforeCreationTime=datetime(2015, 1, 1),
    MaxResults=123,
    NextToken='string'
)
type AdapterId:

string

param AdapterId:

A string containing a unique ID for the adapter to match for when listing adapter versions.

type AfterCreationTime:

datetime

param AfterCreationTime:

Specifies the lower bound for the ListAdapterVersions operation. Ensures ListAdapterVersions returns only adapter versions created after the specified creation time.

type BeforeCreationTime:

datetime

param BeforeCreationTime:

Specifies the upper bound for the ListAdapterVersions operation. Ensures ListAdapterVersions returns only adapter versions created after the specified creation time.

type MaxResults:

integer

param MaxResults:

The maximum number of results to return when listing adapter versions.

type NextToken:

string

param NextToken:

Identifies the next page of results to return when listing adapter versions.

rtype:

dict

returns:

Response Syntax

{
    'AdapterVersions': [
        {
            'AdapterId': 'string',
            'AdapterVersion': 'string',
            'CreationTime': datetime(2015, 1, 1),
            'FeatureTypes': [
                'TABLES'|'FORMS'|'QUERIES'|'SIGNATURES'|'LAYOUT',
            ],
            'Status': 'ACTIVE'|'AT_RISK'|'DEPRECATED'|'CREATION_ERROR'|'CREATION_IN_PROGRESS',
            'StatusMessage': 'string'
        },
    ],
    'NextToken': 'string'
}

Response Structure

  • (dict) --

    • AdapterVersions (list) --

      Adapter versions that match the filtering criteria specified when calling ListAdapters.

      • (dict) --

        Summary info for an adapter version. Contains information on the AdapterId, AdapterVersion, CreationTime, FeatureTypes, and Status.

        • AdapterId (string) --

          A unique identifier for the adapter associated with a given adapter version.

        • AdapterVersion (string) --

          An identified for a given adapter version.

        • CreationTime (datetime) --

          The date and time that a given adapter version was created.

        • FeatureTypes (list) --

          The feature types that the adapter version is operating on.

          • (string) --

        • Status (string) --

          Contains information on the status of a given adapter version.

        • StatusMessage (string) --

          A message explaining the status of a given adapter vesion.

    • NextToken (string) --

      Identifies the next page of results to return when listing adapter versions.

CreateAdapter (new) Link ¶

Creates an adapter, which can be fine-tuned for enhanced performance on user provided documents. Takes an AdapterName and FeatureType. Currently the only supported feature type is QUERIES. You can also provide a Description, Tags, and a ClientRequestToken. You can choose whether or not the adapter should be AutoUpdated with the AutoUpdate argument. By default, AutoUpdate is set to DISABLED.

See also: AWS API Documentation

Request Syntax

client.create_adapter(
    AdapterName='string',
    ClientRequestToken='string',
    Description='string',
    FeatureTypes=[
        'TABLES'|'FORMS'|'QUERIES'|'SIGNATURES'|'LAYOUT',
    ],
    AutoUpdate='ENABLED'|'DISABLED',
    Tags={
        'string': 'string'
    }
)
type AdapterName:

string

param AdapterName:

[REQUIRED]

The name to be assigned to the adapter being created.

type ClientRequestToken:

string

param ClientRequestToken:

Idempotent token is used to recognize the request. If the same token is used with multiple CreateAdapter requests, the same session is returned. This token is employed to avoid unintentionally creating the same session multiple times.

This field is autopopulated if not provided.

type Description:

string

param Description:

The description to be assigned to the adapter being created.

type FeatureTypes:

list

param FeatureTypes:

[REQUIRED]

The type of feature that the adapter is being trained on. Currrenly, supported feature types are: QUERIES

  • (string) --

type AutoUpdate:

string

param AutoUpdate:

Controls whether or not the adapter should automatically update.

type Tags:

dict

param Tags:

A list of tags to be added to the adapter.

  • (string) --

    • (string) --

rtype:

dict

returns:

Response Syntax

{
    'AdapterId': 'string'
}

Response Structure

  • (dict) --

    • AdapterId (string) --

      A string containing the unique ID for the adapter that has been created.

ListAdapters (new) Link ¶

Lists all adapters that match the specified filtration criteria.

See also: AWS API Documentation

Request Syntax

client.list_adapters(
    AfterCreationTime=datetime(2015, 1, 1),
    BeforeCreationTime=datetime(2015, 1, 1),
    MaxResults=123,
    NextToken='string'
)
type AfterCreationTime:

datetime

param AfterCreationTime:

Specifies the lower bound for the ListAdapters operation. Ensures ListAdapters returns only adapters created after the specified creation time.

type BeforeCreationTime:

datetime

param BeforeCreationTime:

Specifies the upper bound for the ListAdapters operation. Ensures ListAdapters returns only adapters created before the specified creation time.

type MaxResults:

integer

param MaxResults:

The maximum number of results to return when listing adapters.

type NextToken:

string

param NextToken:

Identifies the next page of results to return when listing adapters.

rtype:

dict

returns:

Response Syntax

{
    'Adapters': [
        {
            'AdapterId': 'string',
            'AdapterName': 'string',
            'CreationTime': datetime(2015, 1, 1),
            'FeatureTypes': [
                'TABLES'|'FORMS'|'QUERIES'|'SIGNATURES'|'LAYOUT',
            ]
        },
    ],
    'NextToken': 'string'
}

Response Structure

  • (dict) --

    • Adapters (list) --

      A list of adapters that matches the filtering criteria specified when calling ListAdapters.

      • (dict) --

        Contains information on the adapter, including the adapter ID, Name, Creation time, and feature types.

        • AdapterId (string) --

          A unique identifier for the adapter resource.

        • AdapterName (string) --

          A string naming the adapter resource.

        • CreationTime (datetime) --

          The date and time that the adapter was created.

        • FeatureTypes (list) --

          The feature types that the adapter is operating on.

          • (string) --

    • NextToken (string) --

      Identifies the next page of results to return when listing adapters.

CreateAdapterVersion (new) Link ¶

Creates a new version of an adapter. Operates on a provided AdapterId and a specified dataset provided via the DatasetConfig argument. Requires that you specify an Amazon S3 bucket with the OutputConfig argument. You can provide an optional KMSKeyId, an optional ClientRequestToken, and optional tags.

See also: AWS API Documentation

Request Syntax

client.create_adapter_version(
    AdapterId='string',
    ClientRequestToken='string',
    DatasetConfig={
        'ManifestS3Object': {
            'Bucket': 'string',
            'Name': 'string',
            'Version': 'string'
        }
    },
    KMSKeyId='string',
    OutputConfig={
        'S3Bucket': 'string',
        'S3Prefix': 'string'
    },
    Tags={
        'string': 'string'
    }
)
type AdapterId:

string

param AdapterId:

[REQUIRED]

A string containing a unique ID for the adapter that will receive a new version.

type ClientRequestToken:

string

param ClientRequestToken:

Idempotent token is used to recognize the request. If the same token is used with multiple CreateAdapterVersion requests, the same session is returned. This token is employed to avoid unintentionally creating the same session multiple times.

This field is autopopulated if not provided.

type DatasetConfig:

dict

param DatasetConfig:

[REQUIRED]

Specifies a dataset used to train a new adapter version. Takes a ManifestS3Object as the value.

  • ManifestS3Object (dict) --

    The S3 bucket name and file name that identifies the document.

    The AWS Region for the S3 bucket that contains the document must match the Region that you use for Amazon Textract operations.

    For Amazon Textract to process a file in an S3 bucket, the user must have permission to access the S3 bucket and file.

    • Bucket (string) --

      The name of the S3 bucket. Note that the # character is not valid in the file name.

    • Name (string) --

      The file name of the input document. Synchronous operations can use image files that are in JPEG or PNG format. Asynchronous operations also support PDF and TIFF format files.

    • Version (string) --

      If the bucket has versioning enabled, you can specify the object version.

type KMSKeyId:

string

param KMSKeyId:

The identifier for your AWS Key Management Service key (AWS KMS key). Used to encrypt your documents.

type OutputConfig:

dict

param OutputConfig:

[REQUIRED]

Sets whether or not your output will go to a user created bucket. Used to set the name of the bucket, and the prefix on the output file.

OutputConfig is an optional parameter which lets you adjust where your output will be placed. By default, Amazon Textract will store the results internally and can only be accessed by the Get API operations. With OutputConfig enabled, you can set the name of the bucket the output will be sent to the file prefix of the results where you can download your results. Additionally, you can set the KMSKeyID parameter to a customer master key (CMK) to encrypt your output. Without this parameter set Amazon Textract will encrypt server-side using the AWS managed CMK for Amazon S3.

Decryption of Customer Content is necessary for processing of the documents by Amazon Textract. If your account is opted out under an AI services opt out policy then all unencrypted Customer Content is immediately and permanently deleted after the Customer Content has been processed by the service. No copy of of the output is retained by Amazon Textract. For information about how to opt out, see Managing AI services opt-out policy.

For more information on data privacy, see the Data Privacy FAQ.

  • S3Bucket (string) -- [REQUIRED]

    The name of the bucket your output will go to.

  • S3Prefix (string) --

    The prefix of the object key that the output will be saved to. When not enabled, the prefix will be “textract_output".

type Tags:

dict

param Tags:

A set of tags (key-value pairs) that you want to attach to the adapter version.

  • (string) --

    • (string) --

rtype:

dict

returns:

Response Syntax

{
    'AdapterId': 'string',
    'AdapterVersion': 'string'
}

Response Structure

  • (dict) --

    • AdapterId (string) --

      A string containing the unique ID for the adapter that has received a new version.

    • AdapterVersion (string) --

      A string describing the new version of the adapter.

UpdateAdapter (new) Link ¶

Update the configuration for an adapter. FeatureTypes configurations cannot be updated. At least one new parameter must be specified as an argument.

See also: AWS API Documentation

Request Syntax

client.update_adapter(
    AdapterId='string',
    Description='string',
    AdapterName='string',
    AutoUpdate='ENABLED'|'DISABLED'
)
type AdapterId:

string

param AdapterId:

[REQUIRED]

A string containing a unique ID for the adapter that will be updated.

type Description:

string

param Description:

The new description to be applied to the adapter.

type AdapterName:

string

param AdapterName:

The new name to be applied to the adapter.

type AutoUpdate:

string

param AutoUpdate:

The new auto-update status to be applied to the adapter.

rtype:

dict

returns:

Response Syntax

{
    'AdapterId': 'string',
    'AdapterName': 'string',
    'CreationTime': datetime(2015, 1, 1),
    'Description': 'string',
    'FeatureTypes': [
        'TABLES'|'FORMS'|'QUERIES'|'SIGNATURES'|'LAYOUT',
    ],
    'AutoUpdate': 'ENABLED'|'DISABLED'
}

Response Structure

  • (dict) --

    • AdapterId (string) --

      A string containing a unique ID for the adapter that has been updated.

    • AdapterName (string) --

      A string containing the name of the adapter that has been updated.

    • CreationTime (datetime) --

      An object specifying the creation time of the the adapter that has been updated.

    • Description (string) --

      A string containing the description of the adapter that has been updated.

    • FeatureTypes (list) --

      List of the targeted feature types for the updated adapter.

      • (string) --

    • AutoUpdate (string) --

      The auto-update status of the adapter that has been updated.

DeleteAdapter (new) Link ¶

Deletes an Amazon Textract adapter. Takes an AdapterId and deletes the adapter specified by the ID.

See also: AWS API Documentation

Request Syntax

client.delete_adapter(
    AdapterId='string'
)
type AdapterId:

string

param AdapterId:

[REQUIRED]

A string containing a unique ID for the adapter to be deleted.

rtype:

dict

returns:

Response Syntax

{}

Response Structure

  • (dict) --

UntagResource (new) Link ¶

Removes any tags with the specified keys from the specified resource.

See also: AWS API Documentation

Request Syntax

client.untag_resource(
    ResourceARN='string',
    TagKeys=[
        'string',
    ]
)
type ResourceARN:

string

param ResourceARN:

[REQUIRED]

The Amazon Resource Name (ARN) that specifies the resource to be untagged.

type TagKeys:

list

param TagKeys:

[REQUIRED]

Specifies the tags to be removed from the resource specified by the ResourceARN.

  • (string) --

rtype:

dict

returns:

Response Syntax

{}

Response Structure

  • (dict) --

GetAdapter (new) Link ¶

Gets configuration information for an adapter specified by an AdapterId, returning information on AdapterName, Description, CreationTime, AutoUpdate status, and FeatureTypes.

See also: AWS API Documentation

Request Syntax

client.get_adapter(
    AdapterId='string'
)
type AdapterId:

string

param AdapterId:

[REQUIRED]

A string containing a unique ID for the adapter.

rtype:

dict

returns:

Response Syntax

{
    'AdapterId': 'string',
    'AdapterName': 'string',
    'CreationTime': datetime(2015, 1, 1),
    'Description': 'string',
    'FeatureTypes': [
        'TABLES'|'FORMS'|'QUERIES'|'SIGNATURES'|'LAYOUT',
    ],
    'AutoUpdate': 'ENABLED'|'DISABLED',
    'Tags': {
        'string': 'string'
    }
}

Response Structure

  • (dict) --

    • AdapterId (string) --

      A string identifying the adapter that information has been retrieved for.

    • AdapterName (string) --

      The name of the requested adapter.

    • CreationTime (datetime) --

      The date and time the requested adapter was created at.

    • Description (string) --

      The description for the requested adapter.

    • FeatureTypes (list) --

      List of the targeted feature types for the requested adapter.

      • (string) --

    • AutoUpdate (string) --

      Binary value indicating if the adapter is being automatically updated or not.

    • Tags (dict) --

      A set of tags (key-value pairs) associated with the adapter that has been retrieved.

      • (string) --

        • (string) --

AnalyzeDocument (updated) Link ¶
Changes (request)
{'AdaptersConfig': {'Adapters': [{'AdapterId': 'string',
                                  'Pages': ['string'],
                                  'Version': 'string'}]}}

Analyzes an input document for relationships between detected items.

The types of information returned are as follows:

  • Form data (key-value pairs). The related information is returned in two Block objects, each of type KEY_VALUE_SET: a KEY Block object and a VALUE Block object. For example, Name: Ana Silva Carolina contains a key and value. Name: is the key. Ana Silva Carolina is the value.

  • Table and table cell data. A TABLE Block object contains information about a detected table. A CELL Block object is returned for each cell in a table.

  • Lines and words of text. A LINE Block object contains one or more WORD Block objects. All lines and words that are detected in the document are returned (including text that doesn't have a relationship with the value of FeatureTypes).

  • Signatures. A SIGNATURE Block object contains the location information of a signature in a document. If used in conjunction with forms or tables, a signature can be given a Key-Value pairing or be detected in the cell of a table.

  • Query. A QUERY Block object contains the query text, alias and link to the associated Query results block object.

  • Query Result. A QUERY_RESULT Block object contains the answer to the query and an ID that connects it to the query asked. This Block also contains a confidence score.

Selection elements such as check boxes and option buttons (radio buttons) can be detected in form data and in tables. A SELECTION_ELEMENT Block object contains information about a selection element, including the selection status.

You can choose which type of analysis to perform by specifying the FeatureTypes list.

The output is returned in a list of Block objects.

AnalyzeDocument is a synchronous operation. To analyze documents asynchronously, use StartDocumentAnalysis.

For more information, see Document Text Analysis.

See also: AWS API Documentation

Request Syntax

client.analyze_document(
    Document={
        'Bytes': b'bytes',
        'S3Object': {
            'Bucket': 'string',
            'Name': 'string',
            'Version': 'string'
        }
    },
    FeatureTypes=[
        'TABLES'|'FORMS'|'QUERIES'|'SIGNATURES'|'LAYOUT',
    ],
    HumanLoopConfig={
        'HumanLoopName': 'string',
        'FlowDefinitionArn': 'string',
        'DataAttributes': {
            'ContentClassifiers': [
                'FreeOfPersonallyIdentifiableInformation'|'FreeOfAdultContent',
            ]
        }
    },
    QueriesConfig={
        'Queries': [
            {
                'Text': 'string',
                'Alias': 'string',
                'Pages': [
                    'string',
                ]
            },
        ]
    },
    AdaptersConfig={
        'Adapters': [
            {
                'AdapterId': 'string',
                'Pages': [
                    'string',
                ],
                'Version': 'string'
            },
        ]
    }
)
type Document:

dict

param Document:

[REQUIRED]

The input document as base64-encoded bytes or an Amazon S3 object. If you use the AWS CLI to call Amazon Textract operations, you can't pass image bytes. The document must be an image in JPEG, PNG, PDF, or TIFF format.

If you're using an AWS SDK to call Amazon Textract, you might not need to base64-encode image bytes that are passed using the Bytes field.

  • Bytes (bytes) --

    A blob of base64-encoded document bytes. The maximum size of a document that's provided in a blob of bytes is 5 MB. The document bytes must be in PNG or JPEG format.

    If you're using an AWS SDK to call Amazon Textract, you might not need to base64-encode image bytes passed using the Bytes field.

  • S3Object (dict) --

    Identifies an S3 object as the document source. The maximum size of a document that's stored in an S3 bucket is 5 MB.

    • Bucket (string) --

      The name of the S3 bucket. Note that the # character is not valid in the file name.

    • Name (string) --

      The file name of the input document. Synchronous operations can use image files that are in JPEG or PNG format. Asynchronous operations also support PDF and TIFF format files.

    • Version (string) --

      If the bucket has versioning enabled, you can specify the object version.

type FeatureTypes:

list

param FeatureTypes:

[REQUIRED]

A list of the types of analysis to perform. Add TABLES to the list to return information about the tables that are detected in the input document. Add FORMS to return detected form data. Add SIGNATURES to return the locations of detected signatures. Add LAYOUT to the list to return information about the layout of the document. All lines and words detected in the document are included in the response (including text that isn't related to the value of FeatureTypes).

  • (string) --

type HumanLoopConfig:

dict

param HumanLoopConfig:

Sets the configuration for the human in the loop workflow for analyzing documents.

  • HumanLoopName (string) -- [REQUIRED]

    The name of the human workflow used for this image. This should be kept unique within a region.

  • FlowDefinitionArn (string) -- [REQUIRED]

    The Amazon Resource Name (ARN) of the flow definition.

  • DataAttributes (dict) --

    Sets attributes of the input data.

    • ContentClassifiers (list) --

      Sets whether the input image is free of personally identifiable information or adult content.

      • (string) --

type QueriesConfig:

dict

param QueriesConfig:

Contains Queries and the alias for those Queries, as determined by the input.

  • Queries (list) -- [REQUIRED]

    • (dict) --

      Each query contains the question you want to ask in the Text and the alias you want to associate.

      • Text (string) -- [REQUIRED]

        Question that Amazon Textract will apply to the document. An example would be "What is the customer's SSN?"

      • Alias (string) --

        Alias attached to the query, for ease of location.

      • Pages (list) --

        Pages is a parameter that the user inputs to specify which pages to apply a query to. The following is a list of rules for using this parameter.

        • If a page is not specified, it is set to ["1"] by default.

        • The following characters are allowed in the parameter's string: 0 1 2 3 4 5 6 7 8 9 - *. No whitespace is allowed.

        • When using * to indicate all pages, it must be the only element in the list.

        • You can use page intervals, such as [“1-3”, “1-1”, “4-*”]. Where * indicates last page of document.

        • Specified pages must be greater than 0 and less than or equal to the number of pages in the document.

        • (string) --

type AdaptersConfig:

dict

param AdaptersConfig:

Specifies the adapter to be used when analyzing a document.

  • Adapters (list) -- [REQUIRED]

    A list of adapters to be used when analyzing the specified document.

    • (dict) --

      An adapter selected for use when analyzing documents. Contains an adapter ID and a version number. Contains information on pages selected for analysis when analyzing documents asychronously.

      • AdapterId (string) -- [REQUIRED]

        A unique identifier for the adapter resource.

      • Pages (list) --

        Pages is a parameter that the user inputs to specify which pages to apply an adapter to. The following is a list of rules for using this parameter.

        • If a page is not specified, it is set to ["1"] by default.

        • The following characters are allowed in the parameter's string: 0 1 2 3 4 5 6 7 8 9 - *. No whitespace is allowed.

        • When using * to indicate all pages, it must be the only element in the list.

        • You can use page intervals, such as ["1-3", "1-1", "4-*"]. Where * indicates last page of document.

        • Specified pages must be greater than 0 and less than or equal to the number of pages in the document.

        • (string) --

      • Version (string) -- [REQUIRED]

        A string that identifies the version of the adapter.

rtype:

dict

returns:

Response Syntax

{
    'DocumentMetadata': {
        'Pages': 123
    },
    'Blocks': [
        {
            'BlockType': 'KEY_VALUE_SET'|'PAGE'|'LINE'|'WORD'|'TABLE'|'CELL'|'SELECTION_ELEMENT'|'MERGED_CELL'|'TITLE'|'QUERY'|'QUERY_RESULT'|'SIGNATURE'|'TABLE_TITLE'|'TABLE_FOOTER'|'LAYOUT_TEXT'|'LAYOUT_TITLE'|'LAYOUT_HEADER'|'LAYOUT_FOOTER'|'LAYOUT_SECTION_HEADER'|'LAYOUT_PAGE_NUMBER'|'LAYOUT_LIST'|'LAYOUT_FIGURE'|'LAYOUT_TABLE'|'LAYOUT_KEY_VALUE',
            'Confidence': ...,
            'Text': 'string',
            'TextType': 'HANDWRITING'|'PRINTED',
            'RowIndex': 123,
            'ColumnIndex': 123,
            'RowSpan': 123,
            'ColumnSpan': 123,
            'Geometry': {
                'BoundingBox': {
                    'Width': ...,
                    'Height': ...,
                    'Left': ...,
                    'Top': ...
                },
                'Polygon': [
                    {
                        'X': ...,
                        'Y': ...
                    },
                ]
            },
            'Id': 'string',
            'Relationships': [
                {
                    'Type': 'VALUE'|'CHILD'|'COMPLEX_FEATURES'|'MERGED_CELL'|'TITLE'|'ANSWER'|'TABLE'|'TABLE_TITLE'|'TABLE_FOOTER',
                    'Ids': [
                        'string',
                    ]
                },
            ],
            'EntityTypes': [
                'KEY'|'VALUE'|'COLUMN_HEADER'|'TABLE_TITLE'|'TABLE_FOOTER'|'TABLE_SECTION_TITLE'|'TABLE_SUMMARY'|'STRUCTURED_TABLE'|'SEMI_STRUCTURED_TABLE',
            ],
            'SelectionStatus': 'SELECTED'|'NOT_SELECTED',
            'Page': 123,
            'Query': {
                'Text': 'string',
                'Alias': 'string',
                'Pages': [
                    'string',
                ]
            }
        },
    ],
    'HumanLoopActivationOutput': {
        'HumanLoopArn': 'string',
        'HumanLoopActivationReasons': [
            'string',
        ],
        'HumanLoopActivationConditionsEvaluationResults': 'string'
    },
    'AnalyzeDocumentModelVersion': 'string'
}

Response Structure

  • (dict) --

    • DocumentMetadata (dict) --

      Metadata about the analyzed document. An example is the number of pages.

      • Pages (integer) --

        The number of pages that are detected in the document.

    • Blocks (list) --

      The items that are detected and analyzed by AnalyzeDocument.

      • (dict) --

        A Block represents items that are recognized in a document within a group of pixels close to each other. The information returned in a Block object depends on the type of operation. In text detection for documents (for example DetectDocumentText), you get information about the detected words and lines of text. In text analysis (for example AnalyzeDocument), you can also get information about the fields, tables, and selection elements that are detected in the document.

        An array of Block objects is returned by both synchronous and asynchronous operations. In synchronous operations, such as DetectDocumentText, the array of Block objects is the entire set of results. In asynchronous operations, such as GetDocumentAnalysis, the array is returned over one or more responses.

        For more information, see How Amazon Textract Works.

        • BlockType (string) --

          The type of text item that's recognized. In operations for text detection, the following types are returned:

          • PAGE - Contains a list of the LINE Block objects that are detected on a document page.

          • WORD - A word detected on a document page. A word is one or more ISO basic Latin script characters that aren't separated by spaces.

          • LINE - A string of tab-delimited, contiguous words that are detected on a document page.

          In text analysis operations, the following types are returned:

          • PAGE - Contains a list of child Block objects that are detected on a document page.

          • KEY_VALUE_SET - Stores the KEY and VALUE Block objects for linked text that's detected on a document page. Use the EntityType field to determine if a KEY_VALUE_SET object is a KEY Block object or a VALUE Block object.

          • WORD - A word that's detected on a document page. A word is one or more ISO basic Latin script characters that aren't separated by spaces.

          • LINE - A string of tab-delimited, contiguous words that are detected on a document page.

          • TABLE - A table that's detected on a document page. A table is grid-based information with two or more rows or columns, with a cell span of one row and one column each.

          • TABLE_TITLE - The title of a table. A title is typically a line of text above or below a table, or embedded as the first row of a table.

          • TABLE_FOOTER - The footer associated with a table. A footer is typically a line or lines of text below a table or embedded as the last row of a table.

          • CELL - A cell within a detected table. The cell is the parent of the block that contains the text in the cell.

          • MERGED_CELL - A cell in a table whose content spans more than one row or column. The Relationships array for this cell contain data from individual cells.

          • SELECTION_ELEMENT - A selection element such as an option button (radio button) or a check box that's detected on a document page. Use the value of SelectionStatus to determine the status of the selection element.

          • SIGNATURE - The location and confidence score of a signature detected on a document page. Can be returned as part of a Key-Value pair or a detected cell.

          • QUERY - A question asked during the call of AnalyzeDocument. Contains an alias and an ID that attaches it to its answer.

          • QUERY_RESULT - A response to a question asked during the call of analyze document. Comes with an alias and ID for ease of locating in a response. Also contains location and confidence score.

          The following BlockTypes are only returned for Amazon Textract Layout.

          • LAYOUT_TITLE - The main title of the document.

          • LAYOUT_HEADER - Text located in the top margin of the document.

          • LAYOUT_FOOTER - Text located in the bottom margin of the document.

          • LAYOUT_SECTION_HEADER - The titles of sections within a document.

          • LAYOUT_PAGE_NUMBER - The page number of the documents.

          • LAYOUT_LIST - Any information grouped together in list form.

          • LAYOUT_FIGURE - Indicates the location of an image in a document.

          • LAYOUT_TABLE - Indicates the location of a table in the document.

          • LAYOUT_KEY_VALUE - Indicates the location of form key-values in a document.

          • LAYOUT_TEXT - Text that is present typically as a part of paragraphs in documents.

        • Confidence (float) --

          The confidence score that Amazon Textract has in the accuracy of the recognized text and the accuracy of the geometry points around the recognized text.

        • Text (string) --

          The word or line of text that's recognized by Amazon Textract.

        • TextType (string) --

          The kind of text that Amazon Textract has detected. Can check for handwritten text and printed text.

        • RowIndex (integer) --

          The row in which a table cell is located. The first row position is 1. RowIndex isn't returned by DetectDocumentText and GetDocumentTextDetection.

        • ColumnIndex (integer) --

          The column in which a table cell appears. The first column position is 1. ColumnIndex isn't returned by DetectDocumentText and GetDocumentTextDetection.

        • RowSpan (integer) --

          The number of rows that a table cell spans. RowSpan isn't returned by DetectDocumentText and GetDocumentTextDetection.

        • ColumnSpan (integer) --

          The number of columns that a table cell spans. ColumnSpan isn't returned by DetectDocumentText and GetDocumentTextDetection.

        • Geometry (dict) --

          The location of the recognized text on the image. It includes an axis-aligned, coarse bounding box that surrounds the text, and a finer-grain polygon for more accurate spatial information.

          • BoundingBox (dict) --

            An axis-aligned coarse representation of the location of the recognized item on the document page.

            • Width (float) --

              The width of the bounding box as a ratio of the overall document page width.

            • Height (float) --

              The height of the bounding box as a ratio of the overall document page height.

            • Left (float) --

              The left coordinate of the bounding box as a ratio of overall document page width.

            • Top (float) --

              The top coordinate of the bounding box as a ratio of overall document page height.

          • Polygon (list) --

            Within the bounding box, a fine-grained polygon around the recognized item.

            • (dict) --

              The X and Y coordinates of a point on a document page. The X and Y values that are returned are ratios of the overall document page size. For example, if the input document is 700 x 200 and the operation returns X=0.5 and Y=0.25, then the point is at the (350,50) pixel coordinate on the document page.

              An array of Point objects, Polygon, is returned by DetectDocumentText. Polygon represents a fine-grained polygon around detected text. For more information, see Geometry in the Amazon Textract Developer Guide.

              • X (float) --

                The value of the X coordinate for a point on a Polygon.

              • Y (float) --

                The value of the Y coordinate for a point on a Polygon.

        • Id (string) --

          The identifier for the recognized text. The identifier is only unique for a single operation.

        • Relationships (list) --

          A list of relationship objects that describe how blocks are related to each other. For example, a LINE block object contains a CHILD relationship type with the WORD blocks that make up the line of text. There aren't Relationship objects in the list for relationships that don't exist, such as when the current block has no child blocks.

          • (dict) --

            Information about how blocks are related to each other. A Block object contains 0 or more Relation objects in a list, Relationships. For more information, see Block.

            The Type element provides the type of the relationship for all blocks in the IDs array.

            • Type (string) --

              The type of relationship between the blocks in the IDs array and the current block. The following list describes the relationship types that can be returned.

              • VALUE - A list that contains the ID of the VALUE block that's associated with the KEY of a key-value pair.

              • CHILD - A list of IDs that identify blocks found within the current block object. For example, WORD blocks have a CHILD relationship to the LINE block type.

              • MERGED_CELL - A list of IDs that identify each of the MERGED_CELL block types in a table.

              • ANSWER - A list that contains the ID of the QUERY_RESULT block that’s associated with the corresponding QUERY block.

              • TABLE - A list of IDs that identify associated TABLE block types.

              • TABLE_TITLE - A list that contains the ID for the TABLE_TITLE block type in a table.

              • TABLE_FOOTER - A list of IDs that identify the TABLE_FOOTER block types in a table.

            • Ids (list) --

              An array of IDs for related blocks. You can get the type of the relationship from the Type element.

              • (string) --

        • EntityTypes (list) --

          The type of entity.

          The following entity types can be returned by FORMS analysis:

          • KEY - An identifier for a field on the document.

          • VALUE - The field text.

          The following entity types can be returned by TABLES analysis:

          • COLUMN_HEADER - Identifies a cell that is a header of a column.

          • TABLE_TITLE - Identifies a cell that is a title within the table.

          • TABLE_SECTION_TITLE - Identifies a cell that is a title of a section within a table. A section title is a cell that typically spans an entire row above a section.

          • TABLE_FOOTER - Identifies a cell that is a footer of a table.

          • TABLE_SUMMARY - Identifies a summary cell of a table. A summary cell can be a row of a table or an additional, smaller table that contains summary information for another table.

          • STRUCTURED_TABLE - Identifies a table with column headers where the content of each row corresponds to the headers.

          • SEMI_STRUCTURED_TABLE - Identifies a non-structured table.

          EntityTypes isn't returned by DetectDocumentText and GetDocumentTextDetection.

          • (string) --

        • SelectionStatus (string) --

          The selection status of a selection element, such as an option button or check box.

        • Page (integer) --

          The page on which a block was detected. Page is returned by synchronous and asynchronous operations. Page values greater than 1 are only returned for multipage documents that are in PDF or TIFF format. A scanned image (JPEG/PNG) provided to an asynchronous operation, even if it contains multiple document pages, is considered a single-page document. This means that for scanned images the value of Page is always 1.

        • Query (dict) --

          • Text (string) --

            Question that Amazon Textract will apply to the document. An example would be "What is the customer's SSN?"

          • Alias (string) --

            Alias attached to the query, for ease of location.

          • Pages (list) --

            Pages is a parameter that the user inputs to specify which pages to apply a query to. The following is a list of rules for using this parameter.

            • If a page is not specified, it is set to ["1"] by default.

            • The following characters are allowed in the parameter's string: 0 1 2 3 4 5 6 7 8 9 - *. No whitespace is allowed.

            • When using * to indicate all pages, it must be the only element in the list.

            • You can use page intervals, such as [“1-3”, “1-1”, “4-*”]. Where * indicates last page of document.

            • Specified pages must be greater than 0 and less than or equal to the number of pages in the document.

            • (string) --

    • HumanLoopActivationOutput (dict) --

      Shows the results of the human in the loop evaluation.

      • HumanLoopArn (string) --

        The Amazon Resource Name (ARN) of the HumanLoop created.

      • HumanLoopActivationReasons (list) --

        Shows if and why human review was needed.

        • (string) --

      • HumanLoopActivationConditionsEvaluationResults (string) --

        Shows the result of condition evaluations, including those conditions which activated a human review.

    • AnalyzeDocumentModelVersion (string) --

      The version of the model used to analyze the document.

StartDocumentAnalysis (updated) Link ¶
Changes (request)
{'AdaptersConfig': {'Adapters': [{'AdapterId': 'string',
                                  'Pages': ['string'],
                                  'Version': 'string'}]}}

Starts the asynchronous analysis of an input document for relationships between detected items such as key-value pairs, tables, and selection elements.

StartDocumentAnalysis can analyze text in documents that are in JPEG, PNG, TIFF, and PDF format. The documents are stored in an Amazon S3 bucket. Use DocumentLocation to specify the bucket name and file name of the document.

StartDocumentAnalysis returns a job identifier ( JobId) that you use to get the results of the operation. When text analysis is finished, Amazon Textract publishes a completion status to the Amazon Simple Notification Service (Amazon SNS) topic that you specify in NotificationChannel. To get the results of the text analysis operation, first check that the status value published to the Amazon SNS topic is SUCCEEDED. If so, call GetDocumentAnalysis, and pass the job identifier ( JobId) from the initial call to StartDocumentAnalysis.

For more information, see Document Text Analysis.

See also: AWS API Documentation

Request Syntax

client.start_document_analysis(
    DocumentLocation={
        'S3Object': {
            'Bucket': 'string',
            'Name': 'string',
            'Version': 'string'
        }
    },
    FeatureTypes=[
        'TABLES'|'FORMS'|'QUERIES'|'SIGNATURES'|'LAYOUT',
    ],
    ClientRequestToken='string',
    JobTag='string',
    NotificationChannel={
        'SNSTopicArn': 'string',
        'RoleArn': 'string'
    },
    OutputConfig={
        'S3Bucket': 'string',
        'S3Prefix': 'string'
    },
    KMSKeyId='string',
    QueriesConfig={
        'Queries': [
            {
                'Text': 'string',
                'Alias': 'string',
                'Pages': [
                    'string',
                ]
            },
        ]
    },
    AdaptersConfig={
        'Adapters': [
            {
                'AdapterId': 'string',
                'Pages': [
                    'string',
                ],
                'Version': 'string'
            },
        ]
    }
)
type DocumentLocation:

dict

param DocumentLocation:

[REQUIRED]

The location of the document to be processed.

  • S3Object (dict) --

    The Amazon S3 bucket that contains the input document.

    • Bucket (string) --

      The name of the S3 bucket. Note that the # character is not valid in the file name.

    • Name (string) --

      The file name of the input document. Synchronous operations can use image files that are in JPEG or PNG format. Asynchronous operations also support PDF and TIFF format files.

    • Version (string) --

      If the bucket has versioning enabled, you can specify the object version.

type FeatureTypes:

list

param FeatureTypes:

[REQUIRED]

A list of the types of analysis to perform. Add TABLES to the list to return information about the tables that are detected in the input document. Add FORMS to return detected form data. To perform both types of analysis, add TABLES and FORMS to FeatureTypes. All lines and words detected in the document are included in the response (including text that isn't related to the value of FeatureTypes).

  • (string) --

type ClientRequestToken:

string

param ClientRequestToken:

The idempotent token that you use to identify the start request. If you use the same token with multiple StartDocumentAnalysis requests, the same JobId is returned. Use ClientRequestToken to prevent the same job from being accidentally started more than once. For more information, see Calling Amazon Textract Asynchronous Operations.

type JobTag:

string

param JobTag:

An identifier that you specify that's included in the completion notification published to the Amazon SNS topic. For example, you can use JobTag to identify the type of document that the completion notification corresponds to (such as a tax form or a receipt).

type NotificationChannel:

dict

param NotificationChannel:

The Amazon SNS topic ARN that you want Amazon Textract to publish the completion status of the operation to.

  • SNSTopicArn (string) -- [REQUIRED]

    The Amazon SNS topic that Amazon Textract posts the completion status to.

  • RoleArn (string) -- [REQUIRED]

    The Amazon Resource Name (ARN) of an IAM role that gives Amazon Textract publishing permissions to the Amazon SNS topic.

type OutputConfig:

dict

param OutputConfig:

Sets if the output will go to a customer defined bucket. By default, Amazon Textract will save the results internally to be accessed by the GetDocumentAnalysis operation.

  • S3Bucket (string) -- [REQUIRED]

    The name of the bucket your output will go to.

  • S3Prefix (string) --

    The prefix of the object key that the output will be saved to. When not enabled, the prefix will be “textract_output".

type KMSKeyId:

string

param KMSKeyId:

The KMS key used to encrypt the inference results. This can be in either Key ID or Key Alias format. When a KMS key is provided, the KMS key will be used for server-side encryption of the objects in the customer bucket. When this parameter is not enabled, the result will be encrypted server side,using SSE-S3.

type QueriesConfig:

dict

param QueriesConfig:
  • Queries (list) -- [REQUIRED]

    • (dict) --

      Each query contains the question you want to ask in the Text and the alias you want to associate.

      • Text (string) -- [REQUIRED]

        Question that Amazon Textract will apply to the document. An example would be "What is the customer's SSN?"

      • Alias (string) --

        Alias attached to the query, for ease of location.

      • Pages (list) --

        Pages is a parameter that the user inputs to specify which pages to apply a query to. The following is a list of rules for using this parameter.

        • If a page is not specified, it is set to ["1"] by default.

        • The following characters are allowed in the parameter's string: 0 1 2 3 4 5 6 7 8 9 - *. No whitespace is allowed.

        • When using * to indicate all pages, it must be the only element in the list.

        • You can use page intervals, such as [“1-3”, “1-1”, “4-*”]. Where * indicates last page of document.

        • Specified pages must be greater than 0 and less than or equal to the number of pages in the document.

        • (string) --

type AdaptersConfig:

dict

param AdaptersConfig:

Specifies the adapter to be used when analyzing a document.

  • Adapters (list) -- [REQUIRED]

    A list of adapters to be used when analyzing the specified document.

    • (dict) --

      An adapter selected for use when analyzing documents. Contains an adapter ID and a version number. Contains information on pages selected for analysis when analyzing documents asychronously.

      • AdapterId (string) -- [REQUIRED]

        A unique identifier for the adapter resource.

      • Pages (list) --

        Pages is a parameter that the user inputs to specify which pages to apply an adapter to. The following is a list of rules for using this parameter.

        • If a page is not specified, it is set to ["1"] by default.

        • The following characters are allowed in the parameter's string: 0 1 2 3 4 5 6 7 8 9 - *. No whitespace is allowed.

        • When using * to indicate all pages, it must be the only element in the list.

        • You can use page intervals, such as ["1-3", "1-1", "4-*"]. Where * indicates last page of document.

        • Specified pages must be greater than 0 and less than or equal to the number of pages in the document.

        • (string) --

      • Version (string) -- [REQUIRED]

        A string that identifies the version of the adapter.

rtype:

dict

returns:

Response Syntax

{
    'JobId': 'string'
}

Response Structure

  • (dict) --

    • JobId (string) --

      The identifier for the document text detection job. Use JobId to identify the job in a subsequent call to GetDocumentAnalysis. A JobId value is only valid for 7 days.