Skip to main content

Django integration for Veryfi OCR API.

Project description

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 setedup, 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dj-veryfi-0.1.3.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dj_veryfi-0.1.3-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file dj-veryfi-0.1.3.tar.gz.

File metadata

  • Download URL: dj-veryfi-0.1.3.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.10

File hashes

Hashes for dj-veryfi-0.1.3.tar.gz
Algorithm Hash digest
SHA256 02d8da31682293b41ebe1b86703b332330e7d8af6f7b7919d2ef5d391364e794
MD5 b0f9330ff7a7bc4e6e1e8481a999e3fc
BLAKE2b-256 72aa75e62ce6b38159890ef9c6582608a3112cf41132fc83ef1c5dcabcde8705

See more details on using hashes here.

File details

Details for the file dj_veryfi-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: dj_veryfi-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.10

File hashes

Hashes for dj_veryfi-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 3c51b184136f9165975ac93c028c805cdb89dbfa58fd5ae1ae59000d65009f01
MD5 048a4409ecc754a64711e54f01d85e94
BLAKE2b-256 3b856ed422dd60e8f40daa94db8f8f72a131921a5fbb94df0c467e1b13189215

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page