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 model is tuned on Pakistani CNIC layouts for 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.
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
# Get 200 free credits:
# 👉 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)
- •Availability: Served from Cloudflare's global edge network
- •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. Uploaded images are kept for at most 24 hours for quality spot-checks, then deleted.
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.
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.
Romania Carte de Identitate OCR Python SDK
Python Tutorial: Automate KYC in Romania. Extract data from Carte de Identitate using StructOCR Python SDK. Supports native text, front/back sides, and MRZ extraction.
Technical Comparisons & Integrations
Explore platform integrations and competitive analysis
Add Receipt OCR using Cursor in 5 Minutes
Step-by-step guide to integrating the StructOCR receipt API using the Cursor AI code editor. Build expense tracking and receipt scanning tools rapidly.
Add VIN OCR using Cursor in 5 Minutes
Step-by-step guide to integrating the StructOCR VIN scanner API using the Cursor AI code editor. Build automotive and fleet tools rapidly.
Extracting ECR Status & File Numbers: Generic OCR vs. StructOCR Indian Passport API
Learn why generic text extractors fail to capture critical Indian KYC fields like ECR status and File Numbers, and how a specialized API structures this data automatically.
Google Cloud Vision vs. StructOCR API for Shipping Containers
Comparing generic enterprise OCR solutions like Google Cloud Vision against StructOCR's purpose-built API for ISO 6346 shipping container recognition.
Heavy KYC SDKs vs. StructOCR Passport API for Mobile Apps
Discover why modern app developers are abandoning bulky on-device OCR SDKs in favor of lightweight, edge-deployed Passport APIs.
Add Container OCR to Your Lovable.dev App in 5 Minutes
Step-by-step guide to integrating the StructOCR shipping container API into a Lovable.dev app. Build logistics and yard management tools with zero backend.
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.