swarmauri_ocr_pytesseract 0.9.4.dev2__tar.gz → 0.11.0.dev1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- swarmauri_ocr_pytesseract-0.11.0.dev1/PKG-INFO +209 -0
- swarmauri_ocr_pytesseract-0.11.0.dev1/README.md +173 -0
- {swarmauri_ocr_pytesseract-0.9.4.dev2 → swarmauri_ocr_pytesseract-0.11.0.dev1}/pyproject.toml +15 -4
- {swarmauri_ocr_pytesseract-0.9.4.dev2 → swarmauri_ocr_pytesseract-0.11.0.dev1}/swarmauri_ocr_pytesseract/PytesseractOCR.py +29 -10
- swarmauri_ocr_pytesseract-0.9.4.dev2/PKG-INFO +0 -138
- swarmauri_ocr_pytesseract-0.9.4.dev2/README.md +0 -108
- {swarmauri_ocr_pytesseract-0.9.4.dev2 → swarmauri_ocr_pytesseract-0.11.0.dev1}/LICENSE +0 -0
- {swarmauri_ocr_pytesseract-0.9.4.dev2 → swarmauri_ocr_pytesseract-0.11.0.dev1}/swarmauri_ocr_pytesseract/__init__.py +0 -0
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: swarmauri_ocr_pytesseract
|
|
3
|
+
Version: 0.11.0.dev1
|
|
4
|
+
Summary: Local Tesseract OCR adapter for Swarmauri with sync, async, and batch image-to-text workflows.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: swarmauri,ocr,pytesseract,tesseract,image,text,image to text,optical character recognition,document processing,text extraction,async ocr,batch ocr
|
|
8
|
+
Author: Jacob Stewart
|
|
9
|
+
Author-email: jacob@swarmauri.com
|
|
10
|
+
Requires-Python: >=3.10,<3.15
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Development Status :: 3 - Alpha
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: Science/Research
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
18
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
19
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
21
|
+
Classifier: Topic :: Text Processing
|
|
22
|
+
Classifier: Programming Language :: Python
|
|
23
|
+
Classifier: Programming Language :: Python :: 3
|
|
24
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
27
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
28
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
29
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
30
|
+
Requires-Dist: pytesseract (>=0.3.13)
|
|
31
|
+
Requires-Dist: swarmauri_base
|
|
32
|
+
Requires-Dist: swarmauri_core
|
|
33
|
+
Requires-Dist: swarmauri_standard
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+

|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<a href="https://pepy.tech/project/swarmauri_ocr_pytesseract/">
|
|
40
|
+
<img src="https://static.pepy.tech/badge/swarmauri_ocr_pytesseract/month" alt="PyPI - Downloads"/></a>
|
|
41
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_ocr_pytesseract/">
|
|
42
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_ocr_pytesseract.svg"/></a>
|
|
43
|
+
<a href="https://pypi.org/project/swarmauri_ocr_pytesseract/">
|
|
44
|
+
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
45
|
+
<a href="https://pypi.org/project/swarmauri_ocr_pytesseract/">
|
|
46
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_ocr_pytesseract" alt="PyPI - License"/></a>
|
|
47
|
+
<a href="https://pypi.org/project/swarmauri_ocr_pytesseract/">
|
|
48
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_ocr_pytesseract?label=swarmauri_ocr_pytesseract&color=green" alt="PyPI - swarmauri_ocr_pytesseract"/></a>
|
|
49
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
50
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
51
|
+
|
|
52
|
+
# Swarmauri OCR Pytesseract
|
|
53
|
+
|
|
54
|
+
`swarmauri_ocr_pytesseract` is the Swarmauri OCR adapter for running local
|
|
55
|
+
Tesseract-powered image-to-text extraction through a consistent Swarmauri
|
|
56
|
+
`OCRBase` interface. It accepts file paths, raw bytes, or in-memory PIL images
|
|
57
|
+
and supports synchronous, asynchronous, and batch OCR workflows.
|
|
58
|
+
|
|
59
|
+
## Why Use Swarmauri OCR Pytesseract
|
|
60
|
+
|
|
61
|
+
- Use the same OCR component shape across local and pipeline-based Swarmauri
|
|
62
|
+
workflows.
|
|
63
|
+
- Run OCR on local infrastructure without routing images through a hosted API.
|
|
64
|
+
- Tune Tesseract language selection and engine flags for receipts, forms,
|
|
65
|
+
scanned PDFs, screenshots, and other document images.
|
|
66
|
+
- Reuse the same component in parsing, ingestion, indexing, and agent
|
|
67
|
+
workflows.
|
|
68
|
+
|
|
69
|
+
## FAQ
|
|
70
|
+
|
|
71
|
+
> **What does this package do?**
|
|
72
|
+
> It wraps PyTesseract and the local Tesseract binary behind Swarmauri's OCR
|
|
73
|
+
> component interface.
|
|
74
|
+
|
|
75
|
+
> **Does it require a hosted API key?**
|
|
76
|
+
> No. It runs locally, but the host must have the `tesseract` executable and
|
|
77
|
+
> any required language packs installed.
|
|
78
|
+
|
|
79
|
+
> **What image inputs are supported?**
|
|
80
|
+
> File path strings, raw image bytes, and `PIL.Image.Image` instances.
|
|
81
|
+
|
|
82
|
+
> **Can it process multiple images concurrently?**
|
|
83
|
+
> Yes. Use `batch()` for synchronous lists and `abatch()` for async execution
|
|
84
|
+
> with a concurrency limit.
|
|
85
|
+
|
|
86
|
+
## Features
|
|
87
|
+
|
|
88
|
+
- Local OCR backed by [PyTesseract](https://pypi.org/project/pytesseract/) and
|
|
89
|
+
[Tesseract OCR](https://tesseract-ocr.github.io/).
|
|
90
|
+
- Supports configurable `language`, `config`, and explicit `tesseract_cmd`
|
|
91
|
+
resolution.
|
|
92
|
+
- Accepts paths, bytes, and PIL image objects.
|
|
93
|
+
- Includes `extract_text`, `aextract_text`, `batch`, and `abatch` methods.
|
|
94
|
+
- Can report installed OCR languages through `get_supported_languages()`.
|
|
95
|
+
- Supports Python 3.10, 3.11, 3.12, 3.13, and 3.14.
|
|
96
|
+
|
|
97
|
+
## Installation
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
uv add swarmauri_ocr_pytesseract
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
pip install swarmauri_ocr_pytesseract
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
System requirement:
|
|
108
|
+
|
|
109
|
+
- Install the native `tesseract` binary and ensure it is available on `PATH`,
|
|
110
|
+
or set `TESSERACT_CMD` to the executable location.
|
|
111
|
+
|
|
112
|
+
## Usage
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
116
|
+
|
|
117
|
+
ocr = PytesseractOCR(language="eng", config="--psm 6")
|
|
118
|
+
text = ocr.extract_text("docs/invoice.png")
|
|
119
|
+
print(text)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Examples
|
|
123
|
+
|
|
124
|
+
### OCR from image bytes
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from pathlib import Path
|
|
128
|
+
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
129
|
+
|
|
130
|
+
ocr = PytesseractOCR(language="eng")
|
|
131
|
+
image_bytes = Path("receipts/ticket.png").read_bytes()
|
|
132
|
+
text = ocr.extract_text(image_bytes)
|
|
133
|
+
print(text)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### OCR from a PIL image
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from PIL import Image
|
|
140
|
+
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
141
|
+
|
|
142
|
+
image = Image.open("scans/form.png")
|
|
143
|
+
ocr = PytesseractOCR(language="eng", config="--oem 3 --psm 4")
|
|
144
|
+
print(ocr.extract_text(image))
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Async batch OCR
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
import asyncio
|
|
151
|
+
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
152
|
+
|
|
153
|
+
ocr = PytesseractOCR(language="eng")
|
|
154
|
+
|
|
155
|
+
async def run():
|
|
156
|
+
results = await ocr.abatch(
|
|
157
|
+
["scans/page1.png", "scans/page2.png", "scans/page3.png"],
|
|
158
|
+
max_concurrent=2,
|
|
159
|
+
)
|
|
160
|
+
for index, text in enumerate(results, start=1):
|
|
161
|
+
print(index, text[:120])
|
|
162
|
+
|
|
163
|
+
asyncio.run(run())
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
### List installed OCR languages
|
|
167
|
+
|
|
168
|
+
```python
|
|
169
|
+
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
170
|
+
|
|
171
|
+
ocr = PytesseractOCR()
|
|
172
|
+
print(ocr.get_supported_languages())
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Related Packages
|
|
176
|
+
|
|
177
|
+
- [swarmauri_parser_fitzpdf](https://pypi.org/project/swarmauri_parser_fitzpdf/)
|
|
178
|
+
- [swarmauri_parser_pypdf2](https://pypi.org/project/swarmauri_parser_pypdf2/)
|
|
179
|
+
- [swarmauri_parser_pypdftk](https://pypi.org/project/swarmauri_parser_pypdftk/)
|
|
180
|
+
- [swarmauri_ocr_pytesseract](https://pypi.org/project/swarmauri_ocr_pytesseract/)
|
|
181
|
+
|
|
182
|
+
## Swarmauri Foundations
|
|
183
|
+
|
|
184
|
+
- [swarmauri](https://pypi.org/project/swarmauri/)
|
|
185
|
+
- [swarmauri_core](https://pypi.org/project/swarmauri_core/)
|
|
186
|
+
- [swarmauri_base](https://pypi.org/project/swarmauri_base/)
|
|
187
|
+
- [swarmauri_standard](https://pypi.org/project/swarmauri_standard/)
|
|
188
|
+
|
|
189
|
+
## More Documentation
|
|
190
|
+
|
|
191
|
+
- [Tesseract OCR documentation](https://tesseract-ocr.github.io/)
|
|
192
|
+
- [PyTesseract on PyPI](https://pypi.org/project/pytesseract/)
|
|
193
|
+
- [Pillow documentation](https://pillow.readthedocs.io/)
|
|
194
|
+
|
|
195
|
+
## Best Practices
|
|
196
|
+
|
|
197
|
+
- Use `--psm` and `--oem` options through `config` to match the page layout you
|
|
198
|
+
expect.
|
|
199
|
+
- Install the correct `.traineddata` language packs for multilingual OCR.
|
|
200
|
+
- Pre-process noisy or skewed scans before OCR to improve extraction quality.
|
|
201
|
+
- Use PDF parsers when a PDF already contains embedded text; use OCR when the
|
|
202
|
+
PDF or image is scan-only.
|
|
203
|
+
|
|
204
|
+
## License
|
|
205
|
+
|
|
206
|
+
This project is licensed under the Apache-2.0 License.
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
<p align="center">
|
|
4
|
+
<a href="https://pepy.tech/project/swarmauri_ocr_pytesseract/">
|
|
5
|
+
<img src="https://static.pepy.tech/badge/swarmauri_ocr_pytesseract/month" alt="PyPI - Downloads"/></a>
|
|
6
|
+
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_ocr_pytesseract/">
|
|
7
|
+
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_ocr_pytesseract.svg"/></a>
|
|
8
|
+
<a href="https://pypi.org/project/swarmauri_ocr_pytesseract/">
|
|
9
|
+
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
10
|
+
<a href="https://pypi.org/project/swarmauri_ocr_pytesseract/">
|
|
11
|
+
<img src="https://img.shields.io/pypi/l/swarmauri_ocr_pytesseract" alt="PyPI - License"/></a>
|
|
12
|
+
<a href="https://pypi.org/project/swarmauri_ocr_pytesseract/">
|
|
13
|
+
<img src="https://img.shields.io/pypi/v/swarmauri_ocr_pytesseract?label=swarmauri_ocr_pytesseract&color=green" alt="PyPI - swarmauri_ocr_pytesseract"/></a>
|
|
14
|
+
<a href="https://discord.gg/N4UpBuQv8T">
|
|
15
|
+
<img src="https://img.shields.io/badge/Discord-Join%20Chat-5865F2?logo=discord&logoColor=white" alt="Discord"/></a></p>
|
|
16
|
+
|
|
17
|
+
# Swarmauri OCR Pytesseract
|
|
18
|
+
|
|
19
|
+
`swarmauri_ocr_pytesseract` is the Swarmauri OCR adapter for running local
|
|
20
|
+
Tesseract-powered image-to-text extraction through a consistent Swarmauri
|
|
21
|
+
`OCRBase` interface. It accepts file paths, raw bytes, or in-memory PIL images
|
|
22
|
+
and supports synchronous, asynchronous, and batch OCR workflows.
|
|
23
|
+
|
|
24
|
+
## Why Use Swarmauri OCR Pytesseract
|
|
25
|
+
|
|
26
|
+
- Use the same OCR component shape across local and pipeline-based Swarmauri
|
|
27
|
+
workflows.
|
|
28
|
+
- Run OCR on local infrastructure without routing images through a hosted API.
|
|
29
|
+
- Tune Tesseract language selection and engine flags for receipts, forms,
|
|
30
|
+
scanned PDFs, screenshots, and other document images.
|
|
31
|
+
- Reuse the same component in parsing, ingestion, indexing, and agent
|
|
32
|
+
workflows.
|
|
33
|
+
|
|
34
|
+
## FAQ
|
|
35
|
+
|
|
36
|
+
> **What does this package do?**
|
|
37
|
+
> It wraps PyTesseract and the local Tesseract binary behind Swarmauri's OCR
|
|
38
|
+
> component interface.
|
|
39
|
+
|
|
40
|
+
> **Does it require a hosted API key?**
|
|
41
|
+
> No. It runs locally, but the host must have the `tesseract` executable and
|
|
42
|
+
> any required language packs installed.
|
|
43
|
+
|
|
44
|
+
> **What image inputs are supported?**
|
|
45
|
+
> File path strings, raw image bytes, and `PIL.Image.Image` instances.
|
|
46
|
+
|
|
47
|
+
> **Can it process multiple images concurrently?**
|
|
48
|
+
> Yes. Use `batch()` for synchronous lists and `abatch()` for async execution
|
|
49
|
+
> with a concurrency limit.
|
|
50
|
+
|
|
51
|
+
## Features
|
|
52
|
+
|
|
53
|
+
- Local OCR backed by [PyTesseract](https://pypi.org/project/pytesseract/) and
|
|
54
|
+
[Tesseract OCR](https://tesseract-ocr.github.io/).
|
|
55
|
+
- Supports configurable `language`, `config`, and explicit `tesseract_cmd`
|
|
56
|
+
resolution.
|
|
57
|
+
- Accepts paths, bytes, and PIL image objects.
|
|
58
|
+
- Includes `extract_text`, `aextract_text`, `batch`, and `abatch` methods.
|
|
59
|
+
- Can report installed OCR languages through `get_supported_languages()`.
|
|
60
|
+
- Supports Python 3.10, 3.11, 3.12, 3.13, and 3.14.
|
|
61
|
+
|
|
62
|
+
## Installation
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
uv add swarmauri_ocr_pytesseract
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pip install swarmauri_ocr_pytesseract
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
System requirement:
|
|
73
|
+
|
|
74
|
+
- Install the native `tesseract` binary and ensure it is available on `PATH`,
|
|
75
|
+
or set `TESSERACT_CMD` to the executable location.
|
|
76
|
+
|
|
77
|
+
## Usage
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
81
|
+
|
|
82
|
+
ocr = PytesseractOCR(language="eng", config="--psm 6")
|
|
83
|
+
text = ocr.extract_text("docs/invoice.png")
|
|
84
|
+
print(text)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Examples
|
|
88
|
+
|
|
89
|
+
### OCR from image bytes
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
from pathlib import Path
|
|
93
|
+
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
94
|
+
|
|
95
|
+
ocr = PytesseractOCR(language="eng")
|
|
96
|
+
image_bytes = Path("receipts/ticket.png").read_bytes()
|
|
97
|
+
text = ocr.extract_text(image_bytes)
|
|
98
|
+
print(text)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### OCR from a PIL image
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from PIL import Image
|
|
105
|
+
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
106
|
+
|
|
107
|
+
image = Image.open("scans/form.png")
|
|
108
|
+
ocr = PytesseractOCR(language="eng", config="--oem 3 --psm 4")
|
|
109
|
+
print(ocr.extract_text(image))
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
### Async batch OCR
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
import asyncio
|
|
116
|
+
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
117
|
+
|
|
118
|
+
ocr = PytesseractOCR(language="eng")
|
|
119
|
+
|
|
120
|
+
async def run():
|
|
121
|
+
results = await ocr.abatch(
|
|
122
|
+
["scans/page1.png", "scans/page2.png", "scans/page3.png"],
|
|
123
|
+
max_concurrent=2,
|
|
124
|
+
)
|
|
125
|
+
for index, text in enumerate(results, start=1):
|
|
126
|
+
print(index, text[:120])
|
|
127
|
+
|
|
128
|
+
asyncio.run(run())
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### List installed OCR languages
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
135
|
+
|
|
136
|
+
ocr = PytesseractOCR()
|
|
137
|
+
print(ocr.get_supported_languages())
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
## Related Packages
|
|
141
|
+
|
|
142
|
+
- [swarmauri_parser_fitzpdf](https://pypi.org/project/swarmauri_parser_fitzpdf/)
|
|
143
|
+
- [swarmauri_parser_pypdf2](https://pypi.org/project/swarmauri_parser_pypdf2/)
|
|
144
|
+
- [swarmauri_parser_pypdftk](https://pypi.org/project/swarmauri_parser_pypdftk/)
|
|
145
|
+
- [swarmauri_ocr_pytesseract](https://pypi.org/project/swarmauri_ocr_pytesseract/)
|
|
146
|
+
|
|
147
|
+
## Swarmauri Foundations
|
|
148
|
+
|
|
149
|
+
- [swarmauri](https://pypi.org/project/swarmauri/)
|
|
150
|
+
- [swarmauri_core](https://pypi.org/project/swarmauri_core/)
|
|
151
|
+
- [swarmauri_base](https://pypi.org/project/swarmauri_base/)
|
|
152
|
+
- [swarmauri_standard](https://pypi.org/project/swarmauri_standard/)
|
|
153
|
+
|
|
154
|
+
## More Documentation
|
|
155
|
+
|
|
156
|
+
- [Tesseract OCR documentation](https://tesseract-ocr.github.io/)
|
|
157
|
+
- [PyTesseract on PyPI](https://pypi.org/project/pytesseract/)
|
|
158
|
+
- [Pillow documentation](https://pillow.readthedocs.io/)
|
|
159
|
+
|
|
160
|
+
## Best Practices
|
|
161
|
+
|
|
162
|
+
- Use `--psm` and `--oem` options through `config` to match the page layout you
|
|
163
|
+
expect.
|
|
164
|
+
- Install the correct `.traineddata` language packs for multilingual OCR.
|
|
165
|
+
- Pre-process noisy or skewed scans before OCR to improve extraction quality.
|
|
166
|
+
- Use PDF parsers when a PDF already contains embedded text; use OCR when the
|
|
167
|
+
PDF or image is scan-only.
|
|
168
|
+
|
|
169
|
+
## License
|
|
170
|
+
|
|
171
|
+
This project is licensed under the Apache-2.0 License.
|
|
172
|
+
|
|
173
|
+
|
{swarmauri_ocr_pytesseract-0.9.4.dev2 → swarmauri_ocr_pytesseract-0.11.0.dev1}/pyproject.toml
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "swarmauri_ocr_pytesseract"
|
|
3
|
-
version = "0.
|
|
4
|
-
description = "
|
|
3
|
+
version = "0.11.0.dev1"
|
|
4
|
+
description = "Local Tesseract OCR adapter for Swarmauri with sync, async, and batch image-to-text workflows."
|
|
5
5
|
license = "Apache-2.0"
|
|
6
6
|
readme = "README.md"
|
|
7
7
|
repository = "http://github.com/swarmauri/swarmauri-sdk"
|
|
@@ -11,7 +11,13 @@ classifiers = [
|
|
|
11
11
|
"Natural Language :: English",
|
|
12
12
|
"Development Status :: 3 - Alpha",
|
|
13
13
|
"Intended Audience :: Developers",
|
|
14
|
+
"Intended Audience :: Science/Research",
|
|
15
|
+
"Operating System :: OS Independent",
|
|
16
|
+
"Topic :: Multimedia :: Graphics",
|
|
17
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
14
18
|
"Topic :: Software Development :: Libraries :: Application Frameworks",
|
|
19
|
+
"Topic :: Software Development :: Libraries",
|
|
20
|
+
"Topic :: Text Processing",
|
|
15
21
|
"Programming Language :: Python",
|
|
16
22
|
"Programming Language :: Python :: 3",
|
|
17
23
|
"Programming Language :: Python :: 3 :: Only",
|
|
@@ -30,7 +36,12 @@ keywords = [
|
|
|
30
36
|
"tesseract",
|
|
31
37
|
"image",
|
|
32
38
|
"text",
|
|
33
|
-
"
|
|
39
|
+
"image to text",
|
|
40
|
+
"optical character recognition",
|
|
41
|
+
"document processing",
|
|
42
|
+
"text extraction",
|
|
43
|
+
"async ocr",
|
|
44
|
+
"batch ocr",
|
|
34
45
|
]
|
|
35
46
|
|
|
36
47
|
[tool.uv.sources]
|
|
@@ -71,7 +82,7 @@ dev = [
|
|
|
71
82
|
"pytest-xdist>=3.6.1",
|
|
72
83
|
"pytest-json-report>=1.5.0",
|
|
73
84
|
"python-dotenv",
|
|
74
|
-
"
|
|
85
|
+
"httpx>=0.27",
|
|
75
86
|
"flake8>=7.0",
|
|
76
87
|
"pytest-timeout>=2.3.1",
|
|
77
88
|
"ruff>=0.9.9",
|
|
@@ -12,7 +12,8 @@ from swarmauri_base.ocrs.OCRBase import OCRBase
|
|
|
12
12
|
@ComponentBase.register_type(OCRBase, "PytesseractOCR")
|
|
13
13
|
class PytesseractOCR(OCRBase):
|
|
14
14
|
"""
|
|
15
|
-
A model for performing OCR (Optical Character Recognition) using
|
|
15
|
+
A model for performing OCR (Optical Character Recognition) using
|
|
16
|
+
Pytesseract.
|
|
16
17
|
It can process both local images and image bytes, returning extracted text.
|
|
17
18
|
Requires Tesseract-OCR to be installed on the system.
|
|
18
19
|
"""
|
|
@@ -20,7 +21,11 @@ class PytesseractOCR(OCRBase):
|
|
|
20
21
|
tesseract_cmd: str = Field(
|
|
21
22
|
default_factory=lambda: os.environ.get(
|
|
22
23
|
"TESSERACT_CMD",
|
|
23
|
-
(
|
|
24
|
+
(
|
|
25
|
+
"/usr/bin/tesseract"
|
|
26
|
+
if os.path.exists("/usr/bin/tesseract")
|
|
27
|
+
else None
|
|
28
|
+
),
|
|
24
29
|
)
|
|
25
30
|
)
|
|
26
31
|
type: Literal["PytesseractOCR"] = "PytesseractOCR"
|
|
@@ -32,7 +37,9 @@ class PytesseractOCR(OCRBase):
|
|
|
32
37
|
super().__init__(**data)
|
|
33
38
|
pytesseract.pytesseract.tesseract_cmd = self.tesseract_cmd
|
|
34
39
|
|
|
35
|
-
def _process_image(
|
|
40
|
+
def _process_image(
|
|
41
|
+
self, image: Union[str, bytes, Image.Image], **kwargs
|
|
42
|
+
) -> str:
|
|
36
43
|
"""Process an image and return extracted text."""
|
|
37
44
|
try:
|
|
38
45
|
# Handle different input types
|
|
@@ -52,14 +59,18 @@ class PytesseractOCR(OCRBase):
|
|
|
52
59
|
custom_config = kwargs.get("config", self.config)
|
|
53
60
|
lang = kwargs.get("language", self.language)
|
|
54
61
|
|
|
55
|
-
text = pytesseract.image_to_string(
|
|
62
|
+
text = pytesseract.image_to_string(
|
|
63
|
+
img, lang=lang, config=custom_config
|
|
64
|
+
)
|
|
56
65
|
|
|
57
66
|
return text.strip()
|
|
58
67
|
|
|
59
68
|
except Exception as e:
|
|
60
69
|
raise Exception(f"OCR processing failed: {str(e)}")
|
|
61
70
|
|
|
62
|
-
def extract_text(
|
|
71
|
+
def extract_text(
|
|
72
|
+
self, image: Union[str, bytes, Image.Image], **kwargs
|
|
73
|
+
) -> str:
|
|
63
74
|
"""
|
|
64
75
|
Extracts text from an image.
|
|
65
76
|
|
|
@@ -81,7 +92,9 @@ class PytesseractOCR(OCRBase):
|
|
|
81
92
|
Asynchronously extracts text from an image.
|
|
82
93
|
"""
|
|
83
94
|
loop = asyncio.get_event_loop()
|
|
84
|
-
return await loop.run_in_executor(
|
|
95
|
+
return await loop.run_in_executor(
|
|
96
|
+
None, self.extract_text, image, **kwargs
|
|
97
|
+
)
|
|
85
98
|
|
|
86
99
|
def batch(
|
|
87
100
|
self, images: List[Union[str, bytes, Image.Image]], **kwargs
|
|
@@ -130,13 +143,15 @@ class PytesseractOCR(OCRBase):
|
|
|
130
143
|
|
|
131
144
|
def get_supported_languages(self) -> List[str]:
|
|
132
145
|
"""
|
|
133
|
-
Returns a list of supported languages by executing 'tesseract
|
|
146
|
+
Returns a list of supported languages by executing 'tesseract
|
|
147
|
+
--list-langs' command.
|
|
134
148
|
|
|
135
149
|
Returns:
|
|
136
150
|
List[str]: List of available language codes (e.g., ['eng', 'osd'])
|
|
137
151
|
|
|
138
152
|
Raises:
|
|
139
|
-
Exception: If the command execution fails or returns unexpected
|
|
153
|
+
Exception: If the command execution fails or returns unexpected
|
|
154
|
+
output
|
|
140
155
|
"""
|
|
141
156
|
try:
|
|
142
157
|
# Execute tesseract command to list languages
|
|
@@ -154,11 +169,15 @@ class PytesseractOCR(OCRBase):
|
|
|
154
169
|
|
|
155
170
|
# Skip the first line which is the directory info
|
|
156
171
|
# and filter out empty lines
|
|
157
|
-
languages = [
|
|
172
|
+
languages = [
|
|
173
|
+
lang.strip() for lang in output_lines[1:] if lang.strip()
|
|
174
|
+
]
|
|
158
175
|
|
|
159
176
|
return languages
|
|
160
177
|
|
|
161
178
|
except subprocess.CalledProcessError as e:
|
|
162
|
-
raise Exception(
|
|
179
|
+
raise Exception(
|
|
180
|
+
f"Failed to get language list from Tesseract: {e.stderr}"
|
|
181
|
+
)
|
|
163
182
|
except Exception as e:
|
|
164
183
|
raise Exception(f"Error getting supported languages: {str(e)}")
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: swarmauri_ocr_pytesseract
|
|
3
|
-
Version: 0.9.4.dev2
|
|
4
|
-
Summary: Swarmauri Tesseract Image to Text Model
|
|
5
|
-
License-Expression: Apache-2.0
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Keywords: swarmauri,ocr,pytesseract,tesseract,image,text,model
|
|
8
|
-
Author: Jacob Stewart
|
|
9
|
-
Author-email: jacob@swarmauri.com
|
|
10
|
-
Requires-Python: >=3.10,<3.15
|
|
11
|
-
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
-
Classifier: Natural Language :: English
|
|
13
|
-
Classifier: Development Status :: 3 - Alpha
|
|
14
|
-
Classifier: Intended Audience :: Developers
|
|
15
|
-
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
16
|
-
Classifier: Programming Language :: Python
|
|
17
|
-
Classifier: Programming Language :: Python :: 3
|
|
18
|
-
Classifier: Programming Language :: Python :: 3 :: Only
|
|
19
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
23
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
24
|
-
Requires-Dist: pytesseract (>=0.3.13)
|
|
25
|
-
Requires-Dist: swarmauri_base
|
|
26
|
-
Requires-Dist: swarmauri_core
|
|
27
|
-
Requires-Dist: swarmauri_standard
|
|
28
|
-
Description-Content-Type: text/markdown
|
|
29
|
-
|
|
30
|
-

|
|
31
|
-
|
|
32
|
-
<p align="center">
|
|
33
|
-
<a href="https://pepy.tech/project/swarmauri_ocr_pytesseract/">
|
|
34
|
-
<img src="https://static.pepy.tech/badge/swarmauri_ocr_pytesseract/month" alt="PyPI - Downloads"/></a>
|
|
35
|
-
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_ocr_pytesseract/">
|
|
36
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_ocr_pytesseract.svg"/></a>
|
|
37
|
-
<a href="https://pypi.org/project/swarmauri_ocr_pytesseract/">
|
|
38
|
-
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
39
|
-
<a href="https://pypi.org/project/swarmauri_ocr_pytesseract/">
|
|
40
|
-
<img src="https://img.shields.io/pypi/l/swarmauri_ocr_pytesseract" alt="PyPI - License"/></a>
|
|
41
|
-
<a href="https://pypi.org/project/swarmauri_ocr_pytesseract/">
|
|
42
|
-
<img src="https://img.shields.io/pypi/v/swarmauri_ocr_pytesseract?label=swarmauri_ocr_pytesseract&color=green" alt="PyPI - swarmauri_ocr_pytesseract"/></a>
|
|
43
|
-
</p>
|
|
44
|
-
---
|
|
45
|
-
|
|
46
|
-
# Swarmauri OCR Pytesseract
|
|
47
|
-
|
|
48
|
-
OCR adapter for Swarmauri built on top of [PyTesseract](https://pypi.org/project/pytesseract/). Accepts paths, bytes, or PIL images, and exposes synchronous, async, and batch APIs for extracting text.
|
|
49
|
-
|
|
50
|
-
## Features
|
|
51
|
-
|
|
52
|
-
- Wraps Tesseract OCR via PyTesseract behind Swarmauri's `OCRBase` interface.
|
|
53
|
-
- Supports multiple languages (`language` parameter) and custom Tesseract configs.
|
|
54
|
-
- Handles individual, async, and batched OCR calls with optional concurrency limits.
|
|
55
|
-
- Helper to list installed Tesseract languages through `get_supported_languages()`.
|
|
56
|
-
|
|
57
|
-
## Prerequisites
|
|
58
|
-
|
|
59
|
-
- Python 3.10 or newer.
|
|
60
|
-
- [Tesseract OCR](https://github.com/tesseract-ocr/tesseract) installed on the host (`tesseract` binary reachable on `PATH` or via `TESSERACT_CMD`).
|
|
61
|
-
- `pytesseract`, `Pillow`, and related dependencies (installed automatically with this package).
|
|
62
|
-
|
|
63
|
-
## Installation
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
# pip
|
|
67
|
-
pip install swarmauri_ocr_pytesseract
|
|
68
|
-
|
|
69
|
-
# poetry
|
|
70
|
-
poetry add swarmauri_ocr_pytesseract
|
|
71
|
-
|
|
72
|
-
# uv (pyproject-based projects)
|
|
73
|
-
uv add swarmauri_ocr_pytesseract
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
## Quickstart
|
|
77
|
-
|
|
78
|
-
```python
|
|
79
|
-
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
80
|
-
|
|
81
|
-
ocr = PytesseractOCR(language="eng")
|
|
82
|
-
text = ocr.extract_text("docs/invoice.png")
|
|
83
|
-
print(text)
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
## Processing Image Bytes
|
|
87
|
-
|
|
88
|
-
```python
|
|
89
|
-
from pathlib import Path
|
|
90
|
-
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
91
|
-
|
|
92
|
-
png_bytes = Path("receipts/ticket.png").read_bytes()
|
|
93
|
-
ocr = PytesseractOCR(language="eng", config="--psm 6")
|
|
94
|
-
print(ocr.extract_text(png_bytes))
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
## Async and Batch APIs
|
|
98
|
-
|
|
99
|
-
```python
|
|
100
|
-
import asyncio
|
|
101
|
-
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
102
|
-
|
|
103
|
-
ocr = PytesseractOCR(language="fra")
|
|
104
|
-
|
|
105
|
-
async def run_async():
|
|
106
|
-
text = await ocr.aextract_text("scans/document_fr.png")
|
|
107
|
-
print(text)
|
|
108
|
-
|
|
109
|
-
texts = await ocr.abatch([
|
|
110
|
-
"scans/page1.png",
|
|
111
|
-
"scans/page2.png",
|
|
112
|
-
], max_concurrent=2)
|
|
113
|
-
for page, content in enumerate(texts, start=1):
|
|
114
|
-
print(f"Page {page}: {content[:80]}")
|
|
115
|
-
|
|
116
|
-
# asyncio.run(run_async())
|
|
117
|
-
```
|
|
118
|
-
|
|
119
|
-
## List Available Languages
|
|
120
|
-
|
|
121
|
-
```python
|
|
122
|
-
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
123
|
-
|
|
124
|
-
ocr = PytesseractOCR()
|
|
125
|
-
print(ocr.get_supported_languages())
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
## Tips
|
|
129
|
-
|
|
130
|
-
- Set `TESSERACT_CMD` if the binary lives outside standard locations (e.g., Windows installs).
|
|
131
|
-
- Use appropriate page segmentation modes (`--psm`) and OCR engine modes (`--oem`) through the `config` parameter to improve quality.
|
|
132
|
-
- Pre-process images (grayscale, thresholding) before passing them to the OCR for better accuracy.
|
|
133
|
-
- When running in containers, ensure Tesseract language packs (`.traineddata`) are installed for the languages you plan to use.
|
|
134
|
-
|
|
135
|
-
## Want to help?
|
|
136
|
-
|
|
137
|
-
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/contributing.md) that will help you get started.
|
|
138
|
-
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-

|
|
2
|
-
|
|
3
|
-
<p align="center">
|
|
4
|
-
<a href="https://pepy.tech/project/swarmauri_ocr_pytesseract/">
|
|
5
|
-
<img src="https://static.pepy.tech/badge/swarmauri_ocr_pytesseract/month" alt="PyPI - Downloads"/></a>
|
|
6
|
-
<a href="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_ocr_pytesseract/">
|
|
7
|
-
<img alt="Hits" src="https://hits.sh/github.com/swarmauri/swarmauri-sdk/tree/master/pkgs/community/swarmauri_ocr_pytesseract.svg"/></a>
|
|
8
|
-
<a href="https://pypi.org/project/swarmauri_ocr_pytesseract/">
|
|
9
|
-
<img src="https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13%20%7C%203.14-blue" alt="PyPI - Python Version"/></a>
|
|
10
|
-
<a href="https://pypi.org/project/swarmauri_ocr_pytesseract/">
|
|
11
|
-
<img src="https://img.shields.io/pypi/l/swarmauri_ocr_pytesseract" alt="PyPI - License"/></a>
|
|
12
|
-
<a href="https://pypi.org/project/swarmauri_ocr_pytesseract/">
|
|
13
|
-
<img src="https://img.shields.io/pypi/v/swarmauri_ocr_pytesseract?label=swarmauri_ocr_pytesseract&color=green" alt="PyPI - swarmauri_ocr_pytesseract"/></a>
|
|
14
|
-
</p>
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
# Swarmauri OCR Pytesseract
|
|
18
|
-
|
|
19
|
-
OCR adapter for Swarmauri built on top of [PyTesseract](https://pypi.org/project/pytesseract/). Accepts paths, bytes, or PIL images, and exposes synchronous, async, and batch APIs for extracting text.
|
|
20
|
-
|
|
21
|
-
## Features
|
|
22
|
-
|
|
23
|
-
- Wraps Tesseract OCR via PyTesseract behind Swarmauri's `OCRBase` interface.
|
|
24
|
-
- Supports multiple languages (`language` parameter) and custom Tesseract configs.
|
|
25
|
-
- Handles individual, async, and batched OCR calls with optional concurrency limits.
|
|
26
|
-
- Helper to list installed Tesseract languages through `get_supported_languages()`.
|
|
27
|
-
|
|
28
|
-
## Prerequisites
|
|
29
|
-
|
|
30
|
-
- Python 3.10 or newer.
|
|
31
|
-
- [Tesseract OCR](https://github.com/tesseract-ocr/tesseract) installed on the host (`tesseract` binary reachable on `PATH` or via `TESSERACT_CMD`).
|
|
32
|
-
- `pytesseract`, `Pillow`, and related dependencies (installed automatically with this package).
|
|
33
|
-
|
|
34
|
-
## Installation
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
# pip
|
|
38
|
-
pip install swarmauri_ocr_pytesseract
|
|
39
|
-
|
|
40
|
-
# poetry
|
|
41
|
-
poetry add swarmauri_ocr_pytesseract
|
|
42
|
-
|
|
43
|
-
# uv (pyproject-based projects)
|
|
44
|
-
uv add swarmauri_ocr_pytesseract
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## Quickstart
|
|
48
|
-
|
|
49
|
-
```python
|
|
50
|
-
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
51
|
-
|
|
52
|
-
ocr = PytesseractOCR(language="eng")
|
|
53
|
-
text = ocr.extract_text("docs/invoice.png")
|
|
54
|
-
print(text)
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
## Processing Image Bytes
|
|
58
|
-
|
|
59
|
-
```python
|
|
60
|
-
from pathlib import Path
|
|
61
|
-
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
62
|
-
|
|
63
|
-
png_bytes = Path("receipts/ticket.png").read_bytes()
|
|
64
|
-
ocr = PytesseractOCR(language="eng", config="--psm 6")
|
|
65
|
-
print(ocr.extract_text(png_bytes))
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
## Async and Batch APIs
|
|
69
|
-
|
|
70
|
-
```python
|
|
71
|
-
import asyncio
|
|
72
|
-
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
73
|
-
|
|
74
|
-
ocr = PytesseractOCR(language="fra")
|
|
75
|
-
|
|
76
|
-
async def run_async():
|
|
77
|
-
text = await ocr.aextract_text("scans/document_fr.png")
|
|
78
|
-
print(text)
|
|
79
|
-
|
|
80
|
-
texts = await ocr.abatch([
|
|
81
|
-
"scans/page1.png",
|
|
82
|
-
"scans/page2.png",
|
|
83
|
-
], max_concurrent=2)
|
|
84
|
-
for page, content in enumerate(texts, start=1):
|
|
85
|
-
print(f"Page {page}: {content[:80]}")
|
|
86
|
-
|
|
87
|
-
# asyncio.run(run_async())
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## List Available Languages
|
|
91
|
-
|
|
92
|
-
```python
|
|
93
|
-
from swarmauri_ocr_pytesseract import PytesseractOCR
|
|
94
|
-
|
|
95
|
-
ocr = PytesseractOCR()
|
|
96
|
-
print(ocr.get_supported_languages())
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
## Tips
|
|
100
|
-
|
|
101
|
-
- Set `TESSERACT_CMD` if the binary lives outside standard locations (e.g., Windows installs).
|
|
102
|
-
- Use appropriate page segmentation modes (`--psm`) and OCR engine modes (`--oem`) through the `config` parameter to improve quality.
|
|
103
|
-
- Pre-process images (grayscale, thresholding) before passing them to the OCR for better accuracy.
|
|
104
|
-
- When running in containers, ensure Tesseract language packs (`.traineddata`) are installed for the languages you plan to use.
|
|
105
|
-
|
|
106
|
-
## Want to help?
|
|
107
|
-
|
|
108
|
-
If you want to contribute to swarmauri-sdk, read up on our [guidelines for contributing](https://github.com/swarmauri/swarmauri-sdk/blob/master/contributing.md) that will help you get started.
|
|
File without changes
|
|
File without changes
|