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.
Metadata
Release files for pakdocling 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pakdocling-0.0.1.tar.gz | 20.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pakdocling-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 43.6 kB
Release files / pakdocling-0.0.1.tar.gz
| Download URL | pakdocling-0.0.1.tar.gz |
|---|---|
| Size | 20.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
cc433fa3d09e3099c272ba14d10883936688f02b342c61173d546cc2c18b1754
|
|
BLAKE2b-256 checksum How to use checksums |
91c3ff24eaef5dd078c1fc22639e1d295f63089a9df54050ec3260503c00bbcd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.
Transparency logRelease files / pakdocling-0.0.1-py3-none-any.whl
| Download URL | pakdocling-0.0.1-py3-none-any.whl |
|---|---|
| Size | 23.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95bd14e837c927351f4df9c62edaa70ac84da068fb38e05f1d92bad008e3b167
|
|
BLAKE2b-256 checksum How to use checksums |
5f043ea2c06ba3145cfc712a37e829b59f5916094b69475150c67168ddd846c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 11, 2026.
Transparency log