Skip to content
Constaia

Django

Validate documents with AI in Django

A view that forwards request.FILES to the API with httpx. Python SDK coming soon.

Install

pip install httpx

The safe pattern

The browser or app never sees your secret key. The file goes to your server, your server calls Constaia and returns the verdict.

Full guide
verify/views.py
import json
import os

import httpx
from django.http import JsonResponse
from django.views.decorators.http import require_POST

API = "https://api.constaia.com/v1/analyze"


@require_POST
def verify(request):
    upload = request.FILES["file"]
    options = {"expect": "es_dni", "checks": {"not_expired": True}, "storage": "none"}
    res = httpx.post(
        API,
        headers={"Authorization": f"Bearer {os.environ['CONSTAIA_API_KEY']}"},
        files={"file": (upload.name, upload.read(), upload.content_type)},
        data={"options": json.dumps(options)},
        timeout=60,
    )
    res.raise_for_status()
    verdict = res.json()["verdict"]
    return JsonResponse({"status": verdict["status"], "reasons": verdict["reasons"]})

One call. An answer you can act on.

  1. 01

    Send the document and what you expect

    Photo, screenshot or PDF. Set the expected type and the rules: not expired, under 6 months old, in this person's name.

  2. 02

    We read, classify and check

    OCR, AI classification and deterministic validators: PDF417 barcodes, MRZ, ABA routing numbers, dates and totals.

  3. 03

    Get the verdict and delete the file

    valid, invalid or review with reasons in your language. By default the file is deleted when the analysis ends.

And for the record…

Create your account, copy the test key and validate your first document in five minutes.