pakdocling: Pakistani Document Intelligence Library 🇵🇰
An open-source Python library for structured data extraction from Pakistani identity and educational documents.
🎯 The Problem
Existing international OCR engines (EasyOCR, Tesseract, AWS Textract) return unstructured, line-by-line raw text without understanding document layouts. They do not know what a Pakistani CNIC looks like, cannot parse field structures of Pakistani Board Matric/Intermediate certificates, and do not return structured JSON objects with named fields.
Pakistani developers building KYC pipelines, HR systems, and edtech platforms currently solve this manually or with expensive proprietary APIs.
pakdocling solves this by taking document images as input and returning validated, typed Pydantic JSON objects.
📄 Documents Supported in v1
| Document Type | Document ID | Key Fields Extracted |
|---|---|---|
| CNIC | cnic |
13-digit CNIC number, Name, Father/Husband Name, Gender, DOB, Issue Date, Expiry Date, Card Format (old_green vs new_blue Smart Card) |
| Matric Certificate | matric |
Roll No, Registration No, Student Name, Father Name, Board (BISE Lahore, Karachi, Rawalpindi, etc.), Passing Year, Total & Obtained Marks, Grade, Group |
| Intermediate Certificate | intermediate |
Roll No, Reg No, Student Name, Father Name, BISE Board, Passing Year, Total/Obtained Marks, Grade, Group (Pre-Engineering, Pre-Medical, ICS, Commerce) |
| University Degree / Transcript | degree |
Student Name, Father Name, Registration No, Degree Award Title, Major, Issuing University (NUST, FAST, QAU, LUMS, PU, etc.), Graduation Year, CGPA |
🚀 Installation
pip install pakdocling
For development mode:
git clone https://github.com/Epochry-Lab/pakdocling.git
cd pakdocling
pip install -e ".[dev]"
💻 Python API Usage (Docling-Aligned)
1. Converting a Document Image with DocumentConverter
from pakdocling import DocumentConverter
# Initialize converter
converter = DocumentConverter()
# Convert CNIC or educational document image
result = converter.convert("path/to/cnic_card.jpg", doc_type="cnic")
if result.success:
cnic = result.document # Pydantic model (CNICData)
print(f"CNIC Number: {cnic.cnic_number}")
print(f"Name: {cnic.full_name}")
print(f"Father Name: {cnic.father_name}")
print(f"Gender: {cnic.gender}")
print(f"Date of Birth: {cnic.date_of_birth}")
print(f"Card Variant: {cnic.variant}")
# Docling-style export methods
json_output = result.export_to_json(indent=2)
dict_output = result.export_to_dict()
2. Functional Conversion Helper convert()
from pakdocling import convert, DocumentType
result = convert("matric_certificate.png", doc_type=DocumentType.MATRIC)
# Export conversion result directly to formatted JSON
print(result.export_to_json(indent=2))
3. Offline & Fast Testing with MockOCREngine
from pakdocling import DocumentConverter, MockOCREngine
mock_ocr = MockOCREngine(
mock_text="""
NATIONAL UNIVERSITY OF SCIENCES AND TECHNOLOGY (NUST)
Certified that Zainab Shah Registration No NUST-2019-BSCS-0042
is awarded Bachelor of Science in Software Engineering
CGPA: 3.85 / 4.00
Graduation Year: 2023
"""
)
converter = DocumentConverter(ocr_engine=mock_ocr)
result = converter.convert("dummy.png", doc_type="degree")
print(result.document.degree_title) # "Bachelor of Science in Software Engineering"
print(result.document.cgpa) # 3.85
🛠️ Command Line Interface (CLI)
pakdocling comes with a CLI powered by Typer and Rich:
# Check version & supported document schemas
pakdocling info
# Convert document image and print formatted JSON (Docling API)
pakdocling convert sample_cnic.jpg --doc-type cnic
# Convert and save JSON output to file
pakdocling convert degree_transcript.png --doc-type auto -o output.json
🏗️ Core Technology Stack
- EasyOCR: Deep learning OCR engine for multi-language text extraction.
- OpenCV & NumPy: Image preprocessing pipeline (deskewing, noise reduction, adaptive thresholding, contrast enhancement).
- Pydantic v2: Type safety, field validation, and JSON serialization.
- Typer & Rich: Modern terminal CLI interface.
🤝 Contributing
Contributions are welcome! Check out CONTRIBUTING.md to get started.
📜 License
Distributed under the MIT License. See LICENSE for details.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pakdocling-0.0.1.tar.gz.
File metadata
- Download URL: pakdocling-0.0.1.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc433fa3d09e3099c272ba14d10883936688f02b342c61173d546cc2c18b1754
|
|
| MD5 |
a33687dbce183a46fb667c7a95c900d4
|
|
| BLAKE2b-256 |
91c3ff24eaef5dd078c1fc22639e1d295f63089a9df54050ec3260503c00bbcd
|
Provenance
The following attestation bundles were made for pakdocling-0.0.1.tar.gz:
Publisher:
ci.yml on Epochry-Lab/pakdocling
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pakdocling-0.0.1.tar.gz -
Subject digest:
cc433fa3d09e3099c272ba14d10883936688f02b342c61173d546cc2c18b1754 - Sigstore transparency entry: 2426621757
- Sigstore integration time:
-
Permalink:
Epochry-Lab/pakdocling@b441021c16471a0ac3dba9df2b49c956b1b1d527 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/Epochry-Lab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@b441021c16471a0ac3dba9df2b49c956b1b1d527 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pakdocling-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pakdocling-0.0.1-py3-none-any.whl
- Upload date:
- Size: 23.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95bd14e837c927351f4df9c62edaa70ac84da068fb38e05f1d92bad008e3b167
|
|
| MD5 |
0e2ac9bc32dc5ef6c2b1ff9ab9eb6196
|
|
| BLAKE2b-256 |
5f043ea2c06ba3145cfc712a37e829b59f5916094b69475150c67168ddd846c0
|
Provenance
The following attestation bundles were made for pakdocling-0.0.1-py3-none-any.whl:
Publisher:
ci.yml on Epochry-Lab/pakdocling
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pakdocling-0.0.1-py3-none-any.whl -
Subject digest:
95bd14e837c927351f4df9c62edaa70ac84da068fb38e05f1d92bad008e3b167 - Sigstore transparency entry: 2426621858
- Sigstore integration time:
-
Permalink:
Epochry-Lab/pakdocling@b441021c16471a0ac3dba9df2b49c956b1b1d527 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/Epochry-Lab
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@b441021c16471a0ac3dba9df2b49c956b1b1d527 -
Trigger Event:
push
-
Statement type: