Tunisia CIN (Carte d'Identité Nationale) OCR Python SDK
Instantly extract data from Tunisian IDs using our native Python library.

Parsing CIN (Carte d'Identité Nationale) Challenges
Parsing data from Tunisian CIN documents presents unique challenges. Firstly, the presence of both Arabic and Latin script requires OCR engines capable of handling multilingual text accurately. Secondly, variations in layout across different CIN versions and the potential for low-quality prints or damaged cards can significantly impact OCR performance.
Why StructOCR for Tunisia
StructOCR's model is specifically trained on a large dataset of Tunisian CIN documents, ensuring high accuracy in national id ocr processing, even from low-quality images. Our Python SDK simplifies integration with just a few lines of code, abstracting away the complexities of image preprocessing and API communication, and is designed to handle the specific 14 digits structure found in these documents, facilitating kyc automation for financial institutions.
Common Use Cases in Tunisia
- Digital Onboarding: Verify users for Fintech apps in Tunisia.
- Telecom Registration: Automate SIM card registration with CIN (Carte d'Identité Nationale).
- Hotel Check-in: Speed up guest registration workflows.
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.
from structocr import StructOCR
# 🔑 Need a key for Tunisia? Get 200 free credits instantly:
# 👉 https://structocr.com/register
# Initialize with your API Key
client = StructOCR("YOUR_API_KEY_HERE")
def scan_tunisia_id():
# Note: Supports JPG, PNG, WebP (Max 4.5MB)
# Target: CIN (Carte d'Identité Nationale)
image_path = "tunisia_national_id.jpg"
try:
print(f"Scanning {image_path}...")
# The SDK handles file upload and API communication
# It automatically detects that this is a Tunisian 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("✅ Tunisia 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_tunisia_id()Technical Specs
- •Latency: < 4s (Average)
- •Uptime: 99.9% SLA
- •Security: AES-256 Encryption & SOC2 Compliant
- •Input: JPG, PNG, WebP (Max 4.5MB)
- •Output: JSON (Structured Data)
Key Features
- •Native Script Support: Reads English and local characters.
- •Blur Detection: Automatically rejects blurry images.
- •Fraud Check: Validates CIN (Carte d'Identité Nationale) number format.
- •Smart Crop: Removes background noise automatically.
JSON Response Example
The SDK returns a Python dictionary matching this JSON structure.
{
"success": true,
"data": {
"type": "national_id",
"country_code": "TUN",
"nationality": "TUNISIENNE",
"document_number": "01234567",
"card_series": "",
"personal_number": "01234567",
"surname": "TRABELSI",
"given_names": "MOHAMED",
"sex": "M",
"date_of_birth": "1990-05-15",
"place_of_birth": "TUNIS",
"address": "Avenue Habib Bourguiba, Tunis",
"date_of_issue": "2020-01-01",
"date_of_expiry": "2030-01-01",
"issuing_authority": "Ministère de l'Intérieur",
"additional_fields": {
"phone_number": null,
"tramite_number": null,
"ejemplar": null,
"mrz_line_1": null,
"mrz_line_2": null,
"mrz_line_3": null
}
}
}Frequently Asked Questions
Does the Python SDK handle image uploads?
Yes, the SDK automatically handles base64 encoding and file uploads.
Is data stored?
No. Images are processed in-memory and deleted immediately.
How to handle errors?
The SDK result dictionary contains a 'success' boolean and an 'error' message if failed.
You May Also Like
Related tutorials, platform guides, and comparisons
Ukraine National ID OCR Python SDK
Python Tutorial: Automate KYC in Ukraine. Extract data from National ID using StructOCR Python SDK. Supports native text and MRZ extraction.
Uganda National ID Card OCR Python SDK
Python Tutorial: Automate KYC in Uganda. Extract data from National ID Card using StructOCR Python SDK. Supports native text and MRZ extraction.
Egypt ID OCR API & Python SDK
Python Tutorial: Automate KYC in Egypt. Extract data from National IDs using our SDK. Upload an image to test our ID OCR engine live for free.
Côte d'Ivoire CNI (Carte Nationale d'Identité) OCR Python SDK
Python Tutorial: Automate KYC in Côte d'Ivoire. Extract French text, NNI, and validate TD1 MRZ from the ONECI CNI using StructOCR Python SDK.
Kenya National ID (Maisha Card) OCR Python SDK
Python Tutorial: Automate KYC in Kenya. Extract data, Maisha Namba (UPI), and validate TD1 MRZ from National ID (Maisha Card) using StructOCR Python SDK.
Tanzania NIDA Card OCR Python SDK
Python Tutorial: Automate KYC in Tanzania. Extract data from NIDA Card using StructOCR Python SDK. Supports native text and MRZ extraction.
Go National ID OCR API
Upload an image for a free test! High-accuracy National ID data extraction for Go developers. Get structured JSON output via a simple API call, replacing unreliable open-source tools.
Java National ID Parser API
Upload an image for a free test! Eliminate manual data entry for national IDs. Our Java ID card parsing API provides AES-256 encrypted JSON output in <4s average latency, ensuring SOC2 compliant verification.
C# National ID OCR API
Upload an image for a free test! Eliminate manual data entry for national IDs. Integrate hybrid VIZ + MRZ validation into your .NET apps. This C# OCR API delivers structured JSON in <5s average latency, backed by 98.5% uptime SLA and AES-256 encryption.
PHP National ID OCR API
High-accuracy National ID OCR for PHP. Upload an image for a free test! Get structured JSON output from ID card images. A superior alternative to Tesseract. No complex PHP SDK needed.
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 Replit App in 5 Minutes
Step-by-step guide to integrating the StructOCR VIN scanner API into a Replit application. Build automotive and fleet tools using Replit Agent and Secrets.
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.