Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .flake8

This file was deleted.

3 changes: 0 additions & 3 deletions MANIFEST.in

This file was deleted.

7 changes: 0 additions & 7 deletions extras/dev.txt

This file was deleted.

14 changes: 0 additions & 14 deletions extras/docs.txt

This file was deleted.

1 change: 0 additions & 1 deletion extras/pandas.txt

This file was deleted.

1 change: 0 additions & 1 deletion extras/pdf.txt

This file was deleted.

1 change: 0 additions & 1 deletion extras/pdfium.txt

This file was deleted.

1 change: 0 additions & 1 deletion extras/torch.txt

This file was deleted.

90 changes: 90 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
[build-system]
requires = ["setuptools>=77"]
build-backend = "setuptools.build_meta"

[project]
name = "amazon-textract-textractor"
version = "1.10.0"
description = "A package to use AWS Textract services."
readme = "README.md"
license = "Apache-2.0"
requires-python = ">=3.10,<3.15"
keywords = ["amazon", "textract", "aws", "ocr", "document"]
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: 3.14",
"Typing :: Typed",
]
dependencies = [
"amazon-textract-caller>=0.2.4,<1",
"Pillow>=12.3.0",
"tabulate>=0.9,<0.10",
"XlsxWriter>=3.0,<4",
"rapidfuzz>=3.9.6,<4",
"PyYAML>=5.1,<7",
]

[dependency-groups]
test = [
"pytest",
"pytest-cov",
]
docs = [
"sphinx",
"sphinx-rtd-theme",
"jupyterlab",
"pandas",
"pdf2image>=1.16,<1.17",
"pytest",
"Sphinx>=5.1,<5.2",
"nbsphinx>=0.8,<0.9",
"sphinx-rtd-theme>=2.0,<3.0",
"sphinx-argparse>=0.5.1",
"sphinxcontrib-applehelp>=1.0,<1.1",
"sphinxcontrib-devhelp>=1.0,<1.1",
"sphinxcontrib-htmlhelp>=2.0,<2.1",
"sphinxcontrib-jsmath>=1.0,<1.1",
"sphinxcontrib-qthelp>=1.0,<1.1",
"sphinxcontrib-serializinghtml>=1.1,<1.2",
]
dev = [
{ include-group = "test" },
{ include-group = "docs" },
"jupyterlab",
"pandas",
"pdf2image>=1.16,<1.17",
"pytest",
"lxml",
"sentence-transformers>=5.6.0",
]

[project.optional-dependencies]
pandas = ["pandas"]
pdf = ["pdf2image>=1.16,<1.17"]
pdfium = ["pypdfium2"]
torch = ["sentence-transformers>=5.6.0"]

[project.urls]
Homepage = "https://github.com/aws-samples/amazon-textract-textractor"

[project.scripts]
textractor = "textractor.cli.cli:textractor_cli"

[tool.setuptools]
include-package-data = true

[tool.setuptools.packages.find]
exclude = ["docs*", "tests*"]

[tool.setuptools.package-data]
textractor = ["py.typed"]

[tool.flake8]
max-line-length = 120

[tool.pytest.ini_options]
testpaths = ["tests"]
2 changes: 0 additions & 2 deletions setup.cfg

This file was deleted.

74 changes: 0 additions & 74 deletions setup.py

This file was deleted.

15 changes: 15 additions & 0 deletions tests/test_typing_packaging.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pathlib import Path


def test_py_typed_marker_exists():
marker = Path(__file__).resolve().parents[1] / "textractor" / "py.typed"
assert marker.is_file()


def test_public_api_exports():
import textractor

assert textractor.__all__ == ["Document", "LazyDocument", "Textractor"]
assert textractor.Textractor is not None
assert textractor.Document is not None
assert textractor.LazyDocument is not None
4 changes: 4 additions & 0 deletions textractor/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
__version__ = "1.10.0"

from .entities.document import Document
from .entities.lazy_document import LazyDocument
from .textractor import Textractor

__all__ = ["Document", "LazyDocument", "Textractor"]
6 changes: 6 additions & 0 deletions textractor/entities/lazy_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from typing import Any

from textractor.entities.document import Document
from textractor.entities.page import Page
from textractor.parsers.response_parser import parse
from textractor.data.constants import TextractAPI
from textractor.utils.results_utils import results_exist, get_full_json_from_output_config
Expand Down Expand Up @@ -91,6 +92,11 @@ def document(self) -> Document:
"""
return object.__getattribute__(self, "_document")

@property
def pages(self) -> list[Page]:
"""Document pages; loads the Textract job result on first access."""
return self.__getattr__("pages")

def __getattr__(self, __name: str) -> Any:
"""Proxy that gets the Document result when a document property is
accessed. This a blocking call.
Expand Down
Empty file added textractor/py.typed
Empty file.
25 changes: 14 additions & 11 deletions textractor/textractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from botocore.config import Config
from PIL import Image
from copy import deepcopy
from typing import List, Union
from typing import List, Sequence, Union
from textractcaller import (
call_textract,
call_textract_analyzeid,
Expand Down Expand Up @@ -55,6 +55,9 @@

logger = logging.getLogger(__name__)

FileSource = str | bytes | Image.Image
TextractFeatureInput = TextractFeatures | Sequence[TextractFeatures]

try:
try:
import pypdfium2
Expand Down Expand Up @@ -87,10 +90,10 @@ class Textractor:

def __init__(
self,
profile_name: str = None,
region_name: str = None,
profile_name: str | None = None,
region_name: str | None = None,
kms_key_id: str = "",
config: Config = None,
config: Config | None = None,
):
self.profile_name = profile_name
self.region_name = region_name
Expand Down Expand Up @@ -161,7 +164,7 @@ def _get_document_images_from_path(self, filepath: str) -> List[Image.Image]:
return images

def detect_document_text(
self, file_source, save_image: bool = True
self, file_source: FileSource, save_image: bool = True
) -> Document:
"""
Make a call to the SYNC DetectDocumentText API, implicitly parses the response and produces a :class:`Document` object.
Expand Down Expand Up @@ -346,9 +349,9 @@ def start_document_text_detection(

def analyze_document(
self,
file_source,
features,
queries: Union[QueriesConfig, List[Query], List[str]] = None,
file_source: FileSource,
features: TextractFeatureInput,
queries: Union[QueriesConfig, List[Query], List[str]] | None = None,
save_image: bool = True,
) -> Document:
"""
Expand Down Expand Up @@ -459,11 +462,11 @@ def analyze_document(

def start_document_analysis(
self,
file_source: Union[str, bytes, Image.Image],
features,
file_source: FileSource,
features: TextractFeatureInput,
s3_output_path: str = "",
s3_upload_path: str = "",
queries: Union[QueriesConfig, List[Query], List[str]] = None,
queries: Union[QueriesConfig, List[Query], List[str]] | None = None,
client_request_token: str = "",
job_tag: str = "",
save_image: bool = True,
Expand Down
Loading