跳转到主要内容

用于使用AWS Textract服务的包。

项目描述

Textractor

Tests Documentation PyPI version Downloads Code style: black

Textractor 是一个Python包,旨在与Amazon Textract无缝工作,这是一个提供文本识别、表格提取、表单处理等功能文档智能服务。无论您是在制作一次性的脚本还是复杂的分布式文档处理管道,Textractor都能让您轻松使用Textract。

如果您正在寻找其他amazon-textract-*包,您可以通过以下链接找到它们

安装

Textractor可在PyPI上获取,并可通过pip install amazon-textract-textractor进行安装。默认情况下,这将安装适用于lambda执行的Textractor最小版本。以下额外功能可用于添加功能

  • pandaspip install "amazon-textract-textractor[pandas]")安装pandas,用于启用DataFrame和CSV导出。
  • pdfiumpip install amazon-textract-textractor[pdfium])包括pypdfium2,是启用Textractor中PDF光栅化的推荐方式。请注意,使用PDF文件调用Textract时,此功能不是必需的。
  • pdfpip install amazon-textract-textractor[pdf])包括pdf2image,是启用Textractor中PDF光栅化的另一种方法。请注意,使用PDF文件调用Textract时,此功能不是必需的。
  • torchpip install "amazon-textract-textractor[torch]")包括sentence_transformers,用于更好的词搜索和匹配。这将适用于CPU,但比基于非机器学习的方法慢得多。
  • devpip 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

overlay_example

有关更多示例,请参阅文档

测试

该软件包包含调用生产级Textract API的测试。运行测试将对您的AWS账户产生费用。

致谢

这个库是由Srividhya Radhakrishna(@srividh-r)的工作实现的。

贡献

请参阅CONTRIBUTING.md

引用

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上提供

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。

源分布

amazon-textract-textractor-1.8.3.tar.gz (289.6 kB 查看哈希值)

上传时间

构建分布

amazon_textract_textractor-1.8.3-py3-none-any.whl (308.4 kB 查看哈希值)

上传时间 Python 3

由以下机构支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面