stdnum.ke.pin

PIN (Personal Identification Number, Kenya tax number).

The Personal Identification Number (KRA PIN) is an 11 digit unique number that is issued by Kenya Revenue Authority (KRA) for purposes of transacting business with KRA, other Government agencies and service providers. It can be issued for individuals and non-individuals like companies, schools, organisations, etc.

The number consists of 11 characters, where the first one is an A (for individuals) or a P (for non-individuals), the last one is a letter, and the rest are digits.

More information:

>>> validate('P051365947M')
'P051365947M'
>>> validate('A004416331M')
'A004416331M'
>>> validate('12345')
Traceback (most recent call last):
    ...
InvalidLength: ...
>>> validate('V1234567890')
Traceback (most recent call last):
    ...
InvalidFormat: ...
>>> format('a004416331m')
'A004416331M'
stdnum.ke.pin.compact(number)

Convert the number to the minimal representation. This strips the number of any valid separators and removes surrounding whitespace.

stdnum.ke.pin.format(number)

Reformat the number to the standard presentation format.

stdnum.ke.pin.is_valid(number)

Check if the number is a valid Kenya PIN number.

stdnum.ke.pin.validate(number)

Check if the number is a valid Kenya PIN number.

This checks the length and formatting.