Django PDF417 Driver License API
Build a Django form or REST backend that decodes US driver license PDF417 barcodes and returns normalized AAMVA JSON with safe retake handling.
Designing a Safe PDF417 Route in Django
A production Django integration must protect the API key, reject oversized uploads, preserve enough image quality for decoding, and translate recoverable 422 responses into a useful capture experience. A browser-only request would expose credentials and make abuse controls harder.
A Server-Side Django Integration
Django can validate the uploaded image in the view, keep the API key in settings or the environment, and return a retake response without persisting the file. The PDF417 API reference documents the complete response and error model. Identity fields are only returned after deterministic barcode decoding and AAMVA parsing.
Where This Workflow Fits
- Protected upload endpoint: Keep STRUCTOCR_API_KEY inside Django server configuration rather than client code.
- Structured form prefill: Map normalized AAMVA fields into an editable form and require user or staff confirmation.
- Recoverable retake flow: Turn PDF417_NOT_DECODED into a clear request for a sharper, complete license-back image.
Django PDF417 Endpoint
The example accepts image data on the server and calls /v1/driver-license-pdf417. Adapt authentication, authorization, rate limits, and retention to your application.
Prerequisite: pip install structocr django
import json
import os
from django.http import JsonResponse
from django.views.decorators.http import require_POST
from structocr import StructOCR, StructOCRError
client = StructOCR(os.environ["STRUCTOCR_API_KEY"])
@require_POST
def decode_pdf417(request):
image = request.FILES.get("image")
if not image:
return JsonResponse({"error": "image is required"}, status=400)
if image.size > 4_500_000:
return JsonResponse({"error": "image exceeds 4.5 MB"}, status=413)
try:
return JsonResponse(client.scan_driver_license_pdf417(image.read()))
except StructOCRError as error:
return JsonResponse({"error": error.code, "message": str(error)}, status=error.status_code or 502)Technical Specs
- •Endpoint: POST https://api.structocr.com/v1/driver-license-pdf417
- •Authentication: x-api-key kept in server-side configuration
- •Inputs: JPG, PNG, or WebP; maximum 4.5 MB
- •Success: Normalized AAMVA JSON with source set to pdf417
- •Recoverable errors: PDF417_NOT_DECODED and AAMVA_NOT_VALID return HTTP 422
- •Cost: 2 credits for a successful decode; processing failures are refunded
Key Features
- •No browser secret: The capture client uploads to your protected backend route.
- •No AI guessing: Unreadable barcodes fail explicitly instead of producing plausible identity values.
- •Data minimization: The route can select only the fields required by the calling workflow.
- •Operational control: Your service owns authorization, logging redaction, retry behavior, and retention.
Django Response Shape
The example contains fictional identity values. Optional AAMVA elements can be null, and production logs should avoid storing raw identity data.
{
"success": true,
"data": {
"type": "drivers_license",
"source": "pdf417",
"country_code": "USA",
"region": "CA",
"document_number": "SAMPLE1234",
"surname": "SAMPLE",
"given_names": "ALEX MORGAN",
"first_name": "ALEX",
"middle_name": "MORGAN",
"sex": "X",
"date_of_birth": "1990-01-15",
"date_of_issue": "2025-01-15",
"date_of_expiry": "2030-01-15",
"address": "100 EXAMPLE AVE",
"city": "SAMPLE CITY",
"postal_code": "00000",
"vehicle_class": "C",
"restrictions": null,
"endorsements": null,
"document_discriminator": "SAMPLE-DISCRIMINATOR",
"issuer_identification_number": null,
"aamva_version": 10,
"jurisdiction_version": 0
}
}Frequently Asked Questions
Should Django call the PDF417 API from the browser?
No. Keep the StructOCR API key on the server and expose only an authenticated application route to approved clients.
Should the integration retry a 422 response automatically?
No. A 422 normally requires a clearer or correct document image. Ask the user to retake it rather than resending the same input.
Does the endpoint authenticate a driver license?
No. It decodes and parses the AAMVA barcode record. Authenticity and identity decisions require additional controls.
You May Also Like
Related tutorials, platform guides, and comparisons
Massachusetts Driver License OCR: Extract Fields with Python
Extract visible fields from Massachusetts driver license images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.
PHP US Driver License PDF417 API Tutorial
Decode US driver license PDF417 barcodes with PHP. Send a license-back image, parse AAMVA fields, and handle unreadable barcode errors safely.
Minnesota Driver License OCR: Extract Fields with Python
Extract visible fields from Minnesota driver license images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.
Illinois Driver License PDF417 API
Decode the PDF417 barcode on the back of a Illinois driver license or State ID and return normalized AAMVA fields as structured JSON.
South Dakota Driver License OCR: Extract Fields with Python
Extract visible fields from South Dakota driver license images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.
Canada Driver License OCR with Python SDK
Extract structured fields from a Canada provincial driver licence with the StructOCR Python SDK and FastAPI.
Philippines Driver License OCR with Python SDK
Extract structured fields from a Philippines LTO driver's license with the StructOCR Python SDK and FastAPI.
Driver License OCR vs PDF417 API
Compare front-side driver license OCR with back-side PDF417 and AAMVA parsing. Choose the right endpoint or combine both in one review workflow.
Philippines Driver License OCR with Node.js SDK
Extract structured fields from a Philippines LTO driver's license with the StructOCR Node.js SDK and TypeScript + Express.
Canada Driver License OCR with Node.js SDK
Extract structured fields from a Canada provincial driver licence with the StructOCR Node.js SDK and TypeScript + Express.
US State ID Card PDF417 Barcode API
Decode the PDF417 barcode on the back of US state ID cards and return AAMVA fields as JSON, with document_kind to separate ID cards from licenses.
Technical Comparisons & Integrations
Explore platform integrations and competitive analysis
Add Driver's License OCR to Your Bolt.new App in 5 Minutes
Step-by-step guide to integrating the StructOCR Driver's License scanner API into a Bolt.new app. Build car rental and mobility onboarding flows right in your browser.
Add Driver's License OCR using Cursor in 5 Minutes
Step-by-step guide to integrating the StructOCR Driver's License scanner API using the Cursor AI code editor. Build car rental and mobility onboarding flows rapidly.
Add Driver's License OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR Driver's License scanner API into a Lovable.dev app. Build car rental and mobility onboarding flows with zero backend.
Add Driver's License OCR to Your Replit App in 5 Minutes
Step-by-step guide to integrating the StructOCR Driver's License scanner API into a Replit application. Build car rental and mobility onboarding flows using Replit Agent and Secrets.
Add Driver's License OCR to Your v0 App in 5 Minutes
Step-by-step guide to integrating the StructOCR Driver's License scanner API into a v0 by Vercel app. Build car rental and mobility onboarding flows with zero backend.
Add Passport OCR to Your v0 App in 5 Minutes
Step-by-step guide to integrating the StructOCR Passport scanner API into a v0 by Vercel app through a secure Next.js server route.
From tutorial to production in 5 minutes.
You've seen the code. Now get your API key, grab your 200 free credits, and see it work with your own images. No credit card required.