django-ocr
A lightweight Django-based OCR package that extracts text from images and allows dynamic mapping of extracted text into structured dictionaries.
Features
- Extracts text from images using Tesseract OCR
- Supports dynamic key-value mapping for structured text output
- Simple API for easy integration into Django projects
- Fully customizable mapping to extract expected information
Installation
You can install django-ocr using pip:
pip install django-ocr
Dependencies
Make sure you have Tesseract-OCR installed on your system. If not, install it using:
- Ubuntu/Debian:
sudo apt install tesseract-ocr
- MacOS:
brew install tesseract
- Windows: Download and install from Tesseract's official site.
Usage
1. Extract Text from an Image
from django_ocr import process_image
text = process_image("sample_image.png")
print(text) # Output: Extracted text from the image
2. Extract and Map Text to Structured Dictionary
If you have an image containing structured information, such as:
Name: John
Last Name: Doe
You can map it dynamically:
from django_ocr import process_image_with_mapping
image_path = "sample_image.png"
mappings = {
"first_name": ["Name"],
"last_name": ["Last Name"]
}
result = process_image_with_mapping(image_path, mappings)
print(result)
# Output: {'first_name': 'John', 'last_name': 'Doe'}
API Reference
process_image(image_path: str) -> str
Extracts text from an image and returns it as a string.
process_image_with_mapping(image_path: str, mappings: dict) -> dict
Extracts text from an image and maps values to a structured dictionary based on provided mappings.
image_path: Path to the image filemappings: A dictionary where keys represent desired output fields, and values are lists of keywords to search for
Customization
You can define your own mappings dynamically based on the expected text format.
Example for extracting an ID and an email:
mappings = {
"user_id": ["ID", "User ID"],
"email": ["Email"]
}
Contributing
Feel free to open issues or submit pull requests to improve this package!
License
MIT License
Metadata
Release files for django-ocr 0.0.0
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 |
|---|---|---|---|---|
| django_ocr-0.0.0.tar.gz | 6.4 kB | Without provenance | Details for django_ocr-0.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_ocr-0.0.0-py3-none-any.whl | Python 3 | none | any | Details for django_ocr-0.0.0-py3-none-any.whl |
Total release size: 14.8 kB
Release files / django_ocr-0.0.0.tar.gz
| Download URL | django_ocr-0.0.0.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8f5bc289f10df2ca64b5381d9cdf0fda7d26e1bb656c7b19b3919bca8f52fcd3
|
|
BLAKE2b-256 checksum How to use checksums |
2c766aaf9c1243467104109eda0624d1679def1fa143d277d042b053dc80c73d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Release files / django_ocr-0.0.0-py3-none-any.whl
| Download URL | django_ocr-0.0.0-py3-none-any.whl |
|---|---|
| Size | 8.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
445423520de1385d35c0b66629b72e8b0e392c763002c2ab39e683410b60820f
|
|
BLAKE2b-256 checksum How to use checksums |
426df2438b4fdce7d505b929414db6aaca58d3af23e6291c636e60f3667d02b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.11
|
Security for django-ocr 0.0.0
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.