Skip to content

Instantly share code, notes, and snippets.

@symisc
Last active September 1, 2025 05:48
Show Gist options
  • Save symisc/c6e2dd6207dbc63d449b1ac265b6263a to your computer and use it in GitHub Desktop.
Save symisc/c6e2dd6207dbc63d449b1ac265b6263a to your computer and use it in GitHub Desktop.
Scan over 11K ID Documents from over 197 countries using the PixLab DOCSCAN API Endpoint documented at: https://pixlab.io/id-scan-api/docscan
import requests
import json
# Scan over 11K ID Documents from over 197 countries using the PixLab DOCSCAN API Endpoint
# documented at: https://pixlab.io/id-scan-api/docscan
#
# In this example, given a Passport document, extract the passport holder face and convert/parse all Machine Readable Zone
# to textual content ready to be consumed by your application.
#
# PixLab recommend that you connect your AWS S3 bucket via the dashboard at https://console.pixlab.io
# so that any extracted face or MRZ crop is automatically stored on your S3 bucket rather than the PixLab one.
# This feature should give you full control over your analyzed media files.
#
# Refer to the official documentation at: https://ekyc.pixlab.io/docscan for the API reference guide and more code samples.
# You can switch to GET if your input ID DOCUMENT is publicly available
req = requests.post(
'https://api.pixlab.io/docscan',
files = {
'file': open('./local_id_card_image.png', 'rb') # The local Passport image we are going to send to DOCSCAN
},
data={
'type':'passport', # Type of document we are a going to scan,
'key':'PIXLAB_API_KEY' # PixLab API Key - Get yours from https://console.pixlab.io/'
}
)
reply = req.json()
if reply['status'] != 200:
print (reply['error'])
else:
print(f"User Cropped Face: {reply['face_url']}")
# Display all extracted fields from the ID document
print(f"Document Number: {reply['fields']['documentNumber']}")
print(f"Issuing Country: {reply['fields']['issuingCountry']}")
print(f"Full Name: {reply['fields']['fullName']}")
print(f"Date Of Birth: {reply['fields']['dateOfBirth']}")
# Fields that varies from different ID types
if 'checkDigit' in reply['fields']:
print(f"\tCheck Digit: {reply['fields']['checkDigit']}")
if 'nationality' in reply['fields']:
print(f"\tNationality: {reply['fields']['nationality']}")
if 'sex' in reply['fields']:
print(f"\tSex: {reply['fields']['sex']}")
if 'dateOfExpiry' in reply['fields']:
print(f"\tDate Of Expiry: {reply['fields']['dateOfExpiry']}")
if 'personalNumber' in reply['fields']:
print(f"\tPersonal Number: {reply['fields']['personalNumber']}")
if 'finalcheckDigit' in reply['fields']:
print(f"\tFinal Check Digit: {reply['fields']['finalcheckDigit']}")
@symisc
Copy link
Author

symisc commented Jun 19, 2024

Scan over 11K ID Documents from over 197 countries using the PixLab DOCSCAN API Endpoint documented at: https://pixlab.io/id-scan-api/docscan

Given a government issued passport document, extract the user face and parse all MRZ fields.

PixLab recommend that you connect your AWS S3 bucket via the dashboard at https://console.pixlab.io/ so that any extracted face or MRZ crop is automatically stored on your S3 bucket rather than the PixLab one. This feature should give you full control over your analyzed media files.

Refer to the official documentation at: https://pixlab.io/id-scan-api/docscan for the API reference guide and more code samples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment