Pakistan CNIC OCR Python SDK
Instantly extract data from Pakistani IDs using our native Python library.

Parsing CNIC Challenges
Parsing Pakistani CNICs (Computerized National Identity Cards) presents unique challenges. First, the dual-language format, with both English and Urdu script, often confuses generic OCR models. Second, significant variations exist between card versions, and common issues like lamination glare or print fading can drastically reduce data extraction accuracy.
Why StructOCR for Pakistan
Our AI model is pre-trained on tens of thousands of Pakistani CNIC samples, achieving over 99% accuracy on key fields like name, ID number, and dates. This advanced national id ocr technology expertly handles both English and Urdu script, and is designed to recognize the specific 14 digits structure inherent in Pakistani identification. The StructOCR Python SDK abstracts all complexity, enabling you to integrate robust ID parsing into your application in minutes, not weeks.
Common Use Cases in Pakistan
- Digital Onboarding: Verify users for Fintech apps, e-wallets, and banking services.
- Telecom Registration: Automate SIM card registration and biometric verification workflows.
- Automated KYC/AML: Streamline compliance checks and reduce manual data entry for financial institutions.
Live Demo: ID card scanner
No registration required. Upload a file to test the extraction.
Drop files here or click to browse
JPG · PNG · WebP · up to 500 files · max 4.5 MB each
Python SDK Integration
Install the SDK via pip: `pip install structocr`. Then use the following code.
Prerequisite: Python 3.6+ and `structocr` library installed.
Prefer another stack? Open the Node.js SDK + Express integration.
from structocr import StructOCR
# 💰 Save 30%+ vs competitors. Get 200 free credits instantly:
# 👉 https://structocr.com/register
# Initialize with your API Key
client = StructOCR("YOUR_API_KEY_HERE")
def scan_pakistan_id():
# Note: Supports JPG, PNG, WebP (Max 4.5MB)
# Target: CNIC
image_path = "pakistan_national_id.jpg"
try:
print(f"Scanning {image_path}...")
# The SDK handles file upload and API communication
# It automatically detects that this is a Pakistani document
result = client.scan_national_id(image_path)
# Check success flag (SDK returns a dict matching the JSON response)
if result.get('success'):
data = result['data']
print("✅ Pakistan Extraction Successful!")
# Basic Identity
print(f"Region: {data.get('country_code')} (Series: {data.get('card_series')})")
print(f"Name: {data.get('given_names')} {data.get('surname')}")
print(f"ID Number: {data.get('document_number')}")
# Critical Field: Personal Identity Number (CNP/CPF/NIN)
print(f"Personal #: {data.get('personal_number')}")
# Demographics
print(f"DOB: {data.get('date_of_birth')} ({data.get('sex')})")
print(f"Address: {data.get('address')}")
else:
print(f"❌ Extraction Failed: {result.get('error')}")
except Exception as e:
# Handle SDK or Network errors
print(f"An error occurred: {e}")
if __name__ == "__main__":
scan_pakistan_id()Technical Specs
- •Latency: < 2s (Average)
- •Uptime: 99.9% SLA
- •Security: AES-256 Encryption & SOC2 Compliant
- •Input: JPG, PNG, PDF (Max 5MB)
- •Output: JSON (Structured Data)
Key Features
- •Bilingual Support: Natively reads both English and Urdu script with high precision.
- •Blur & Glare Detection: Automatically rejects low-quality or reflective images.
- •Data Validation: Performs checksum validation on the CNIC number to flag potential fakes.
- •AI-Powered Cropping: Automatically detects and crops the ID card from any background.
JSON Response Example
The SDK returns a Python dictionary matching this JSON structure.
{
"success": true,
"data": {
"type": "national_id",
"country_code": "PAK",
"nationality": "PAKISTANI",
"document_number": "35202-1234567-1",
"card_series": null,
"personal_number": "35202-1234567-1",
"surname": "KHAN",
"given_names": "IMRAN AHMED",
"sex": "M",
"date_of_birth": "1990-05-15",
"place_of_birth": "LAHORE",
"address": "House 10, Street 5, Sector F-8/3, Islamabad",
"date_of_issue": "2020-01-01",
"date_of_expiry": "2030-01-01",
"issuing_authority": "Government of Pakistan"
}
}Frequently Asked Questions
Does the Python SDK handle image uploads?
Yes, the SDK automatically handles image validation, base64 encoding, and secure file uploads to our API.
Is our data stored?
No. We operate under a strict zero-retention policy. Images and data are processed in-memory and permanently deleted immediately after processing.
Can it read both the front and back of the CNIC?
Yes, you can process both sides. The API will intelligently merge the data from the front (personal details) and back (address) into a single, consolidated JSON response.
How do you handle errors?
The SDK result object contains a 'success' boolean and an 'error' message. We provide clear error codes for issues like blurry images, invalid API keys, or unsupported files.
You May Also Like
Related tutorials, platform guides, and comparisons
Pakistan Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Pakistan passports with a server-side integration.
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.
Ethiopia Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Ethiopia passports with a server-side integration.
Italy Passport OCR with Python SDK
Use the official StructOCR Python SDK and FastAPI to extract structured MRZ and VIZ data from Italy passports with a server-side integration.
Python HIN OCR API SDK
Tutorial: Extract HIN using the StructOCR Python SDK. Upload an image for a free test! Perfect for marine data pipelines, ETL workflows, and automated watercraft valuations.
US Driver License OCR with Python SDK
Extract structured fields from a United States state-issued driver license with the StructOCR Python SDK and FastAPI.
Spain DNI (DNIe) OCR Python SDK
Python Tutorial: Automate KYC in Spain. Extract data from DNI (DNIe) using StructOCR Python SDK. Supports native text and MRZ extraction.
Serbia Lična karta OCR Python SDK
Python Tutorial: Automate KYC in Serbia. Extract data from Lična karta using StructOCR Python SDK. Supports native text and MRZ extraction.
Senegal Carte d'Identité CEDEAO OCR Python SDK
Python Tutorial: Automate KYC in Senegal. Extract data from Carte d'Identité CEDEAO using StructOCR Python SDK. Supports native text and MRZ extraction.
South Africa Smart ID Card OCR Python SDK
Python Tutorial: Automate KYC in South Africa. Extract data from Smart ID Card using StructOCR Python SDK. Supports native text and MRZ extraction.
Technical Comparisons & Integrations
Explore platform integrations and competitive analysis
Add National ID OCR to Your Bolt.new App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a Bolt.new app. Build KYC and identity verification flows right in your browser.
Add National ID OCR using Cursor in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API using the Cursor AI code editor. Build KYC and identity verification flows rapidly.
Add National ID OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a Lovable.dev app. Build KYC and identity verification flows with zero backend.
Add National ID OCR to Your Replit App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a Replit application. Build KYC and identity verification flows using Replit Agent and Secrets.
Add National ID OCR to Your v0 App in 5 Minutes
Step-by-step guide to integrating the StructOCR National ID scanner API into a v0 by Vercel app. Build KYC and identity verification flows with zero backend.
Add VIN OCR to Your Bolt.new App in 5 Minutes
Step-by-step guide to integrating the StructOCR VIN scanner API into a Bolt.new app. Build automotive and fleet tools right in your browser.
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.