Skip to content
Constaia

Django

Validate documents with AI in Django

A view forwards the uploaded files to Constaia. The Python SDK is coming soon.

Installation

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 result. If you do not have a server, use the widget with a publishable key.

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

    A photo, screenshot or PDF. Say which document you expect and the rules: in date, less than 6 months old, in this person's name.

  2. 02

    We read, classify and check

    Text reading, AI classification and fixed checks: Spanish ID number check letter, machine readable zone, IBAN, dates and totals.

  3. 03

    Get the verdict and the file is deleted

    Valid, invalid or review, with the reasons in your language. By default, the file is deleted at the end unless it needs review.

And for the record…

Create your free account and validate your first document in five minutes. No card required.