Pakistan Driver License OCR API with Python

Extract licence number, names, dates, and vehicle class from the Pakistan provincial driving licence with the StructOCR Python SDK.

Reading the provincial driving licence

Licences are issued by provincial authorities, so card layouts differ between Punjab, Sindh, and other provinces; most carry the holder’s CNIC number. Typing these fields by hand slows down rental, onboarding, and fleet workflows and introduces formatting errors.

Structured Fields from One API Call

The Driver License OCR API returns the licence number, holder name, dates, issuing authority, address, and vehicle class when they are printed and legible; missing fields are null. Try a sample with the free driver license scanner. For coverage, pricing, and the full field list, see the driver license OCR API overview.

Common Integration Scenarios

  • Vehicle rental: Pre-fill Pakistan licence details before handover and keep the agent’s confirmation step.
  • Driver onboarding: Move licence fields into a review queue without retyping the card.
  • Fleet records: Track licence classes and expiry dates for internal compliance reminders.
Need more testing? Create a free account to get 200 free credits (equals 100 Driver License scans).

Pakistan Driver License OCR API with Python

The official Python SDK reads a local file and calls /v1/driver-license from your backend.

Prerequisite: `pip install structocr`; set the server-side `STRUCTOCR_API_KEY` environment variable.

Prefer another stack? Open the Node.js SDK + Express integration.

import os
from structocr import StructOCR

client = StructOCR(os.environ["STRUCTOCR_API_KEY"])
result = client.scan_driver_license("driver-license.jpg")

if result.get("success"):
    data = result["data"]
    print(data.get("document_number"))
    print(data.get("given_names"), data.get("surname"))
else:
    print(result.get("error"))

Technical Specs

  • •Endpoint: POST /v1/driver-license
  • •Input: Base64-encoded JPG, PNG, WebP, or PDF in JSON (Max 4.5MB)
  • •Authentication: Server-side x-api-key header handled by the SDK
  • •Cost: 2 credits per successful scan; failed requests are not billed
  • •Output: Structured JSON

Key Features

  • •Local layout: Handles the provincial driving licence layout and its printed field labels.
  • •Licence fields: Returns licence number, vehicle class, and validity dates when visible.
  • •Normalized dates: Dates are returned as YYYY-MM-DD regardless of the printed format.
  • •Server-side key: The SDK keeps your API key on the backend.

JSON Response Example

Fictional values showing the normalized shape; fields not present on the card are null.

{
  "success": true,
  "data": {
    "type": "drivers_license",
    "country_code": "PAK",
    "region": "Punjab",
    "personal_number": "35202-0000000-0",
    "surname": "KHAN",
    "given_names": "AYESHA",
    "sex": null,
    "date_of_birth": "1990-04-12",
    "place_of_birth": null,
    "date_of_issue": "2023-05-02",
    "date_of_expiry": "2033-05-01",
    "date_of_first_issue": null,
    "issuing_authority": "PUNJAB",
    "address": null,
    "vehicle_class": "M.CAR",
    "extra_details": {},
    "document_number": "LHR-000123"
  }
}

Frequently Asked Questions

Which fields does the API return for a Pakistan licence?

Typically country_code, region, document_number, personal_number, names, sex, birth details, issue and expiry dates, issuing_authority, address, and vehicle_class, when printed and legible.

Does OCR verify that the licence is valid?

No. It extracts printed data. Validity and authenticity checks need the issuing authority’s records or your own review process.

Is there a version for the other SDK language?

Yes. A paired Node.js version of this tutorial covers the same document.

You May Also Like

Related tutorials, platform guides, and comparisons

Country Tutorial

Pakistan Driver License OCR API with Node.js

Extract licence number, names, dates, and vehicle class from the Pakistan provincial driving licence with the StructOCR Node.js SDK.

Node.js · Driver License
Country Tutorial

Indiana Driver License OCR: Extract Fields with Python

Extract visible fields from Indiana driver license images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.

Python · Driver License
Country Tutorial

Illinois Driver License OCR: Extract Fields with Python

Extract visible fields from Illinois driver license images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.

Python · Driver License
Country Tutorial

Arkansas Driver License OCR: Extract Fields with Python

Extract visible fields from Arkansas driver license images into JSON. Map identifiers, names and dates, with a review workflow for incomplete results.

Python · Driver License
Country Tutorial

Australia Driver License OCR with Python SDK

Extract structured fields from a Australia state or territory driver licence with the StructOCR Python SDK and FastAPI.

Python · Driver License
Country Tutorial

Brazil Driver License OCR with Python SDK

Extract structured fields from a Brazil Carteira Nacional de Habilitação (CNH) with the StructOCR Python SDK and FastAPI.

Python · Driver License
Country Tutorial

Brazil Driver License OCR with Node.js SDK

Extract structured fields from a Brazil Carteira Nacional de Habilitação (CNH) with the StructOCR Node.js SDK and TypeScript + Express.

Node.js · Driver License
Country Tutorial

Peru Driver License OCR API with Node.js

Extract licence number, names, dates, and vehicle class from the Peru Licencia de Conducir (brevete) with the StructOCR Node.js SDK.

Node.js · Driver License
Country Tutorial

Australia Driver License OCR with Node.js SDK

Extract structured fields from a Australia state or territory driver licence with the StructOCR Node.js SDK and TypeScript + Express.

Node.js · Driver License
Country Tutorial

Pakistan CNIC OCR with Node.js SDK

Extract CNIC number, names, dates and other visible fields from Computerized National Identity Card (CNIC) with the StructOCR Node.js SDK and Express.

Node.js · National ID

Technical Comparisons & Integrations

Explore platform integrations and competitive analysis

Integration

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.

Driver License
Integration

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.

Driver License
Integration

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.

Driver License
Integration

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.

Driver License
Integration

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.

Driver License
Comparison

AWS Textract vs. StructOCR API for Indian Passport Back Page Extraction

Why generic OCR fails at parsing the back page of Indian passports, and how a dedicated KYC API instantly extracts structured addresses, PIN codes, and family details.

Comparison

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.

Instant Access Cancel Anytime No Credit Card