Docket Analyzer OCR
Installation
pip install 'docketanalyzer[ocr]'
Local Usage
Process a document:
from docketanalyzer.ocr import pdf_document
path = 'path/to/doc.pdf
doc = pdf_document(path) # the input can also be raw bytes
doc.process()
for page in doc:
for block in page:
for line in block:
pass
You can also stream pages as they are processed:
doc = pdf_document(path)
for page in doc.stream():
print(page.text)
Pages, blocks, and lines have common attributes:
# where item is a page, block, or line
item.data # A dictionary representation of the item and it's children
item.text # The item's text content
item.page_num # The page the item appears on
item.i # The item-level index
item.id # A unique id constructed from the item and it's parents index (e.g. 3-2-1 for the first line in the second block on the third page).
item.bbox # Bounding box (blocks and lines only)
item.clip() # Extract element as an image from the original pdf
Blocks also have a block type attribute:
print(block.block_type) # 'title', 'text', 'figure', etc.
Save and load data:
# Saving a document
doc.save('doc.json')
# Loading a document
doc = pdf_document(path, load='doc.json')
Remote Usage
You can also serve this tool with Docker.
docker pull nadahlberg/docketanalyzer-ocr:latest
docker run --gpus all -p 8000:8000 nadahlberg/docketanalyzer-ocr:latest
And then use process the document in remote mode:
doc = pdf_document(path, remote=True) # pass endpoint_url if not using localhost
for page in doc.stream():
print(page.text)
S3 Support
When using the remote service, if you want to avoid sending the file in a POST request, configure your S3 credentials. Your document will be temporarily pushed to your bucket to be retrieved by the service.
To configure your S3 credentials run:
da configure s3
Or set the following in your env:
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_S3_BUCKET_NAME
AWS_S3_ENDPOINT_URL
Usage is identical. We default to using S3 if credentials are available. You can control this explicitly by passing use_s3=False to pdf_document.
Serverless Support
For serverless usage you can deploy this to RunPod. To get set up:
- Create a serverless worker on RunPod using the docker container.
nadahlberg/docketanalyzer-ocr:latest
- Add the following custom run command.
python -u handler.py
- Add your S3 credentials to the RunPod worker.
AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY
AWS_S3_BUCKET_NAME
AWS_S3_ENDPOINT_URL
- On your local machine, configure your RunPod key and the worker id.
You can run:
da configure runpod
Or set the following in your env:
RUNPOD_API_KEY
RUNPOD_OCR_ENDPOINT_ID
Usage is otherwise identical, just use remote=True with pdf_document
Metadata
Release files for docketanalyzer-ocr 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| docketanalyzer_ocr-0.1.9.tar.gz | 19.2 kB | Without provenance | Details for docketanalyzer_ocr-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| docketanalyzer_ocr-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for docketanalyzer_ocr-0.1.9-py3-none-any.whl |
Total release size: 38.9 kB
Release files / docketanalyzer_ocr-0.1.9.tar.gz
| Download URL | docketanalyzer_ocr-0.1.9.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0d1af6599266630c104c15c0f9e3ce62ec12708dc38bfd031f5adcd880e8ffc4
|
|
BLAKE2b-256 checksum How to use checksums |
0385511acd7f24275fd9e7dcd689371e1f50ee4f6246b08e54b849e5151e659a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Release files / docketanalyzer_ocr-0.1.9-py3-none-any.whl
| Download URL | docketanalyzer_ocr-0.1.9-py3-none-any.whl |
|---|---|
| Size | 19.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e0d7903cd98f03b1b600ea541f7ad6dade4b331d61eab7b118222015bc0eb865
|
|
BLAKE2b-256 checksum How to use checksums |
1b5b5da7426580e692d7846a208ae7a76f6d3a36b85d617cb1799a743fed8df7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Security for docketanalyzer-ocr 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.