用于使用AWS Textract服务的包。
项目描述
Textractor 是一个Python包,旨在与Amazon Textract无缝工作,这是一个提供文本识别、表格提取、表单处理等功能文档智能服务。无论您是在制作一次性的脚本还是复杂的分布式文档处理管道,Textractor都能让您轻松使用Textract。
如果您正在寻找其他amazon-textract-*包,您可以通过以下链接找到它们
- amazon-textract-caller(简化调用Amazon Textract,无需额外依赖)
- amazon-textract-response-parser(解析Textract API返回的JSON响应)
- amazon-textract-overlayer(在文档图像上的文档实体周围绘制边界框)
- amazon-textract-prettyprinter(将Amazon Textract响应转换为CSV、文本、markdown等)
- amazon-textract-geofinder(使用帮助在文档中通过几何和关系导航的方法提取特定信息,例如层次化的键/值对)
安装
Textractor可在PyPI上获取,并可通过pip install amazon-textract-textractor
进行安装。默认情况下,这将安装适用于lambda执行的Textractor最小版本。以下额外功能可用于添加功能
pandas
(pip install "amazon-textract-textractor[pandas]"
)安装pandas,用于启用DataFrame和CSV导出。pdfium
(pip install amazon-textract-textractor[pdfium]
)包括pypdfium2
,是启用Textractor中PDF光栅化的推荐方式。请注意,使用PDF文件调用Textract时,此功能不是必需的。pdf
(pip install amazon-textract-textractor[pdf]
)包括pdf2image
,是启用Textractor中PDF光栅化的另一种方法。请注意,使用PDF文件调用Textract时,此功能不是必需的。torch
(pip install "amazon-textract-textractor[torch]"
)包括sentence_transformers
,用于更好的词搜索和匹配。这将适用于CPU,但比基于非机器学习的方法慢得多。dev
(pip install "amazon-textract-textractor[dev]"
)包括上述所有依赖项以及测试代码所需的所有其他内容。
您可以通过用逗号分隔标签来选择几个额外功能,例如pip install "amazon-textract-textractor[pdf,torch]"
。
文档
最新发布版本的生成文档可通过此处访问:aws-samples.github.io/amazon-textract-textractor/
示例
虽然这里展示了简单的示例集合,但文档中有更多示例和具体的案例研究,这将帮助您开始。
设置
您只需要这两行就可以使用Textractor。Textractor实例可以在多个请求之间重用,适用于同步和异步请求。
from textractor import Textractor
extractor = Textractor(profile_name="default")
文本识别
# file_source can be an image, list of images, bytes or S3 path
document = extractor.detect_document_text(file_source="tests/fixtures/single-page-1.png")
print(document.lines)
#[Textractor Test, Document, Page (1), Key - Values, Name of package: Textractor, Date : 08/14/2022, Table 1, Cell 1, Cell 2, Cell 4, Cell 5, Cell 6, Cell 7, Cell 8, Cell 9, Cell 10, Cell 11, Cell 12, Cell 13, Cell 14, Cell 15, Selection Element, Selected Checkbox, Un-Selected Checkbox]
表格提取
from textractor.data.constants import TextractFeatures
document = extractor.analyze_document(
file_source="tests/fixtures/form.png",
features=[TextractFeatures.TABLES]
)
# Saves the table in an excel document for further processing
document.tables[0].to_excel("output.xlsx")
表单提取
from textractor.data.constants import TextractFeatures
document = extractor.analyze_document(
file_source="tests/fixtures/form.png",
features=[TextractFeatures.FORMS]
)
# Use document.get() to search for a key with fuzzy matching
document.get("email")
# [E-mail Address : johndoe@gmail.com]
分析ID
document = extractor.analyze_id(file_source="tests/fixtures/fake_id.png")
print(document.identity_documents[0].get("FIRST_NAME"))
# 'MARIA'
收据处理(分析费用)
document = extractor.analyze_expense(file_source="tests/fixtures/receipt.jpg")
print(document.expense_documents[0].summary_fields.get("TOTAL")[0].text)
# '$1810.46'
如果这里未涵盖您的用例或您正在寻找异步使用示例,请参阅我们的示例集合。
CLI
Textractor还包含textractor
脚本,它支持在终端中直接调用、打印和叠加。
textractor analyze-document tests/fixtures/amzn_q2.png output.json --features TABLES --overlay TABLES
有关更多示例,请参阅文档。
测试
该软件包包含调用生产级Textract API的测试。运行测试将对您的AWS账户产生费用。
致谢
这个库是由Srividhya Radhakrishna(@srividh-r)的工作实现的。
贡献
引用
Textractor可以使用以下方式引用
@software{amazontextractor,
author = {Belval, Edouard and Delteil, Thomas and Schade, Martin and Radhakrishna, Srividhya},
title = {{Amazon Textractor}},
url = {https://github.com/aws-samples/amazon-textract-textractor},
version = {1.8.3},
year = {2024}
}
或使用CITATION.cff文件。
许可
本库根据Apache 2.0许可证授权。
Excavator图像由macrovector在Freepik上提供
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源分布
构建分布
哈希值 for amazon_textract_textractor-1.8.3-py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 4cab6f0736b150496fb595b394249d428dd5dd9259b403e31be2ae65bcfe7f85 |
|
MD5 | 9b88a4546a11f9729263fec871f246a4 |
|
BLAKE2b-256 | 097e899d25fe8514c49dc3ae35f364b34be413a714576233652425ab7f026b1b |