Implement a Minimalistic KYC Form & Identify Verification Check
Tags: devops, python, php, webdev
Published: 2020-12-22 13:09:15

---
title: Implement a Minimalistic KYC Form & Identify Verification Check
published: true
description: Learn how to automate users identify verification check including Passports scanning using PHP or Python via the PixLab API
tags: devops, python, php, webdev
---

In this post, you will learn how to make use of the [PixLab API](https://pixlab.io) to implement a **minimalistic KYC (<em>Know Your Customer</em>) form for your webapps**, and verify the authenticity of the personal information submitted by any of your users using an image upload of their ID card or Passport. Let's dive in!

## Table Of Contents
* [The Process of ID Verification](#chapter-1)
* [The PixLab API](#chapter-3)
* [Code Samples](#chapter-4)
* [Conclusion](#chapter-5)

##The Process of ID Verification <a name="chapter-1"></a>

Many services have been long-time accepting ID or Passports as identification documents from their customers to complete their KYC (Know Your Customer) form as required by the legislation in force. This is especially true and enforced for the Finance, HR or Travel sectors. In most cases, a human operator will verify the authenticity of the submitted document and grant validation or reject it.

Needless to say, the verification process has been manual for a very long time. We can all agree that lining up and wait for one guy to verify our documents takes too much time. Let's not forget that this process is prone to errors.

Things can get really complicated if you have hundreds of KYC forms to checks, but also if your clients differ in nationality. Quickly, you will find yourself drowning in physical copies of passports in different languages that you can not even understand. Let alone the potential legal problems you can face with passport copies laying around the office. 
As a developer, you may have thought about how you can solve this problem. Well, an automated & safe solution for ID verification is more than required!

##The PixLab API <a name="chapter-3"></a>

![PixLab Logo](https://dev-to-uploads.s3.amazonaws.com/i/afyk4pum0gltyuj63i9t.png)

PixLab is a ML focused, SaaS platform offering Machine Vision & Media Processing APIs for developers via a straightforward [Web](https://pixlab.io/cmdls) or [Offline](https://sod.pixlab.io) SDKs. PixLab API feature set includes but not not limited to:
* [Passports & ID Cards](https://blog.pixlab.io/2020/06/passport-docscan-api-endpoint) document scanning using state-of-the-art Machine Learning models via straightforward HTTP Rest API as shown in this [Python](https://gist.github.com/symisc/3a8df5c54e427ec1781515ceb27965e4) & [PHP](https://gist.github.com/symisc/ca211ac7ff38ddcaab102e98fe5a7fa9) gists and **publicly available** via the /<a href="https://pixlab.io/cmd?id=docscan">docscan</a> API endpoint.
* Board of face analysis API endpoints including <a href="https://pixlab.io/cmd?id=facedetect">face detection</a>, <a href="https://pixlab.io/cmd?id=facelandmarks">landmarks extraction</a>, <a href="https://pixlab.io/cmd?id=facecompare">facial recognition</a>, <a href="https://pixlab.io/cmd?id=nsfw">content moderation</a> and <a href="https://pixlab.io/cmdls">many more</a>.
* On the fly image encryption, conversion, compression and full support for HTTP/2 and HTTP/3(QUIC) within the release of the [PixLab API 1.9.72](https://blog.pixlab.io/2020/08/pixlab-api-1972-released).
* Proxy for AWS S3 and other cloud storage providers.
* Over 130 Machine Vision &amp; Media Processing <a href="https://pixlab.io/cmdls">API endpoints</a>.

### Python/PHP Code Samples<a name="chapter-4"></a>

Given an input Passport Specimen as follow:

![Passport Specimen](https://dev-to-uploads.s3.amazonaws.com/i/iiwojhqcdbn1q3x42sq9.png)

Process Passport Machine Readable Zone, Detect & Extract any present face and finally transform raw MRZ data into text content in the JSON format ready to be consumed by your app. The JSON object output should look like the following:

![PIXLAB DOCSCAN OUTPUT](https://dev-to-uploads.s3.amazonaws.com/i/egh28xvpn8pfrbx8wf7m.png)

The result above was obtained via the following Pyhton gist:

```python
import requests
import json

# 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 your dashboard at https://pixlab.io/dashboard
# so that any cropped face or MRZ crop is stored automatically on your S3 bucket rather than the PixLab one.
# This feature should give you full control over your analyzed media files.
#
# https://pixlab.io/#/cmd?id=docscan for additional information.

req = requests.get('https://api.pixlab.io/docscan',params={
	'img':'https://i.stack.imgur.com/oJY2K.png', # Passport sample
	'type':'passport', # Type of document we are a going to scan
	'key':'Pixlab_key'
})
reply = req.json()
if reply['status'] != 200:
	print (reply['error'])
else:
	print ("User Cropped Face: " + reply['face_url'])
	print ("MRZ Cropped Image: " + reply['mrz_img_url'])
	print ("Raw MRZ Text: " + reply['mrz_raw_text'])
	print ("MRZ Fields: ")
	# Display all parsed MRZ fields
	print ("\tIssuing Country: " + reply['fields']['issuingCountry'])
	print ("\tFull Name: "       + reply['fields']['fullName'])
	print ("\tDocument Number: " + reply['fields']['documentNumber'])
	print ("\tCheck Digit: "   + reply['fields']['checkDigit'])
	print ("\tNationality: "   + reply['fields']['nationality'])
	print ("\tDate Of Birth: " + reply['fields']['dateOfBirth'])
	print ("\tSex: "           + reply['fields']['sex'])
	print ("\tDate Of Expiry: "    + reply['fields']['dateOfExpiry'])
	print ("\tPersonal Number: "   + reply['fields']['personalNumber']) # Optional field and may not be returned when not set by the issuing country.
	print ("\tFinal Check Digit: " + reply['fields']['finalcheckDigit'])
```

* Python Gist Source Code: https://github.com/symisc/pixlab/blob/master/python/passport_scan.py

The same logic using **PHP** now:

{% gist https://gist.github.com/symisc/ca211ac7ff38ddcaab102e98fe5a7fa9 %}

Regardless of the underlying programming language, the logic is always same. We made a simple HTTP GET request with the input Passport image URL as a sole parameter. Most [PixLab endpoints](https://pixlab.io/cmdls) support multiple HTTP methods so you can easily switch to POST based requests if you want to upload your images & videos directly from your mobile or web app for analysis. Back to our sample, only a single API endpoint is needed for our official document scanning task:

1. [docscan](https://pixlab.io/cmd?id=docscan) is the sole endpoint needed for such a task. It support various ID cards besides Passports & Visas and does face extraction automatically for you.
2. PixLab recommend that you connect your AWS S3 bucket via the [dashboard](https://pixlab.io/dashboard) 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.
3. finally, take a look at the *docscan* endpoint [documentation](https://pixlab.io/cmd?id=docscan) for additional information such as the set of scanned fields, where face crops are stored, how to process PDF documents instead of images and so forth.

## Conclusion <a name="chapter-5"></a>

And that's it. Scanning government-issued documents for your app is as easy as it gets. You don't need to have advanced Machine Learning or Devops skills since the endpoint does all the heavy lifting for you and you can automate the scanning process for your KYC tasks. If you would love to test with different languages, or to try other Pixlab's endpoints, please check them out here at our [Github repository](https://github.com/symisc/pixlab).

{% github symisc/pixlab %}