A library to validate and extract information from national id numbers
Project description
A library for validating national id numbers and extracting any embedded data from them.
Currenty only South Africa and Zimbabwe are implemented but more countries will be added over time
Installation
pip install id-validation
Usage
from id_validation import ValidatorFactory
validator = ValidatorFactory.get_validator("ZW")
# Use the validate method to test whether a number is valid or not according to country-specific rules
assert validator.validate("50-025544-Q-12")
# The extract data method returns any data that might be encoded into the id number. This is country specific.
data = validator.extract_data("50-025544-Q-12")
assert data["registration_region"] == "Mutasa"
assert data["district"] == "Chivi"
assert data["sequence_number"] == "025544"
Countries
The following codes are available:
ZA - South Africa
ZA_OLD - South African (Apartheid-era). See the note below for more information
ZW - Zimbabwe
South Africa (ZA)
South African ids contain the following information:
- Date of birth
- Gender
- Citizenship (citizen or permanent resident)
>>> import id_validation
>>> from id_validation import ValidatorFactory
>>> validator = ValidatorFactory.get_validator("ZA")
>>> validator.validate("7106245929185")
True
>>> validator.extract_data("7106245929185")
{'dob': datetime.datetime(1971, 6, 24, 0, 0), 'gender': <GENDER.MALE: 1>, 'checksum': 5, 'citizenship': <CITIZENSHIP_TYPE.PERMANENT_RESIDENT: 1>}
South Africa - Apartheid-era (ZA_OLD)
Apartheid-era South African ids contain the following information:
- Date of birth
- Gender
- Race
>>> import id_validation
>>> from id_validation import ValidatorFactory
>>> validator = ValidatorFactory.get_validator("ZA_OLD")
>>> validator.validate("7106245929185")
True
>>> validator.extract_data("7106245929185")
{'dob': datetime.datetime(1971, 6, 24, 0, 0), 'gender': <GENDER.MALE: 1>, 'checksum': 5, 'race': <RACE.CAPE_COLOURED: 1>}
Note
These id numbers were used during the Apartheid-era. They encoded the race of the ID holder. The 1986 Identification Act removed this identifier and all id numbers were changed to the more modern version which only encodes citizenship. This validator is included for completeness. I have never seen an old id number in any dataset I have ever worked with, so avoid using it unless you are sure that your ids are pre-1986. More information can be found here
Zimbabwe (ZW)
Zimbabwe IDs contain the following information:
- Registration region
- Father's district
>>> import id_validation
>>> from id_validation import ValidatorFactory
>>> validator = ValidatorFactory.get_validator("ZW")
>>> validator.validate("50-025544-Q-12")
True
>>> validator.extract_data("50-025544-Q-12")
{'registration_region': 'Mutasa', 'district': 'Chivi', 'sequence_number': '025544'}
BOTSWANA (BW)
Note - the validation logic has been implemented from anecdotal information available online and not against official documentation.
>>> import id_validation
>>> from id_validation import ValidatorFactory
>>> validator = ValidatorFactory.get_validator("BW")
>>> validator.validate("379219515")
True
>>> validator.extract_data("379219515")
{'gender': 'Male'}
Project 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
File details
Details for the file id-validation-0.4.1.tar.gz
.
File metadata
- Download URL: id-validation-0.4.1.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b93be240fb54d345a621b133d19f4b306c75bc3f56b840f66af3b43629371452 |
|
MD5 | 226ef53e051cb41d866156f9bc792ed3 |
|
BLAKE2b-256 | 613df7f6e36d32ec312d99b6145675758f2608146e6831c19622389bf54351d8 |
File details
Details for the file id_validation-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: id_validation-0.4.1-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1b53c8fb7fe9d85aa4c9d2c57d5d001cb64e74409bd5fee5a1eedd41fda2bb6 |
|
MD5 | 4b86493e9195d92d3c1bd2c5558331fb |
|
BLAKE2b-256 | 2a53a5ac9571c3a91357e9e34b72bcbc9d1aa34f0f26064f1df9c84e0a1966b7 |