Skip to main content

Django Veryfi OCR API Integration

As the title says, its a Django integration for Veryfi OCR API. For now, it can auto OCR receipts or invoices documents by using dj_veryfi.fields.OCRInvoiceOrReceiptField model field. It derives from django.db.models.JSONField model field and, takes a additional parameter upload_to which specifies the path where the file should be saved according to current defined Django STORAGE.

Requirements

Python 3 Django >= 3.2.20 Veryfi 3.3.0

How it works

Once you have defined a model field as dj_veryfi.fields.OCRInvoiceOrReceiptField, you can assign a file-like instance to an instance model field of dj_veryfi.fields.OCRInvoiceOrReceiptField, then, before saving the model, it gonna hit the Veryfi OCR API to extract information and persists it as JSON into datababse. When the field instance is acceesed after extraction it returns a OCRData instance which has the file descriptor and the JSON data.

How to install

pip install dj-veryfi

Setup

Add dj_veryfi into INSTALLED_APPS and set the Veryfi API authentication information into settings.py as described bellow:

...
INSTALLED_APS = [
...
"dj_veryfi"
]
...
# Veryfi access settings
VERYFI_CLIENT_ID = "Your client ID"
VERYFI_CLIENT_SECRET = "Your client secret"
VERYFI_USERNAME = "Your username"
VERYFI_API_KEY = "Your api key"

Usage

Once you have a django project, dj-veryfi installed and set up, just declare your model field as dj_veryfi.fields.OCRInvoiceOrReceiptField, as bellow.

from django.db import models
from dj_veryfi.fields import OCRInvoiceOrReceiptField

class Document(models.Model):
    created_at = models.Datetime.FIeld(auto_now_add=True)
    name = models.CharFied(max_length=100)
    ocr_data = OCRInvoiceOrReceiptField(upload_to="receipts/") 

Note, the upload_to attribute is a relative path which will append to MEDIA_ROOT settings variable.

Now, you can just assign a file-like object to Document.ocr_data save the model and, the information from receipt or invoice file will be extracted and saved as json into database.

Trade-Offs

I have chosen to extend the field from django.db.models.JSONField because the extracted data comes as JSON and I had to do nothing related to querying.

If I had chosen another model field type like FileField to get a shortcut to manage files and save them as JSON, I would have had trouble with how to query it into the database, due to JSON querying definition is not that simple.

So, it seems easier to me to avoid dealing with querying definitions when it comes to JSON querying, due to JSONField comes with "query thing" already done and deal with managing the files from where the information was extracted is easier.

Metadata

Release files for dj-veryfi 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dj-veryfi 0.1.9
File Size Uploaded
dj-veryfi-0.1.9.tar.gz 4.6 kB Details

Release files / dj-veryfi-0.1.9.tar.gz

Download URL dj-veryfi-0.1.9.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8181e33a07a860346a8572f608923fb32443ddb9651a8eac86cf01c86a55cd45
BLAKE2b-256 checksum
How to use checksums
ab4691f9927250e6f805d764e144fa09d691a7d61cae16d2bc9887b348e77fbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.10

Release history Release notifications | RSS feed

This release

0.1.9 This release

1 release file

0.1.8

2 release files

0.1.7

2 release files

0.1.5

2 release files

0.1.4

1 release file

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page