# stdnum.id.nik

NIK (Nomor Induk Kependudukan, Indonesian identity number).

The Nomor Induk Kependudukan (NIK, Population Identification Number, sometimes known as Nomor Kartu Tanda Penduduk or Nomor KTP) is issued to Indonesian citizens.

The number consists of 16 digits in the format PPRRSSDDMMYYXXXX where PPRRSS (province, city/district, sub-district) indicates the place of residence when the number was issued. It is followed by a DDMMYY date of birth (for female 40 is added to the day). The last 4 digits are used to make the number unique.

More information:

- https://id.wikipedia.org/wiki/Nomor_Induk_Kependudukan

    >>> validate('3171011708450001')
    '3171011708450001'
    >>> validate('31710117084500')
    Traceback (most recent call last):
        ...
    InvalidLength: ...
    >>> validate('9971011708450001')  # invalid province
    Traceback (most recent call last):
        ...
    InvalidComponent: ...
    >>> get_birth_date('3171015708450001')
    datetime.date(1945, 8, 17)
    >>> get_birth_date('3171012902001234')  # 1900-02-29 doesn't exist
    datetime.date(2000, 2, 29)
    >>> get_birth_date('3171013002001234')  # 1900-20-30 doesn't exist
    Traceback (most recent call last):
        ...
    InvalidComponent: ...

stdnum.id.nik.compact(number: str) → str

  Convert the number to the minimal representation.

  This strips the number of any valid separators and removes surrounding whitespace.

stdnum.id.nik.get_birth_date(number: str, minyear: int = 1920) → date

  Get the birth date from the person’s NIK.

  Note that the number only encodes the last two digits of the year so this may be a century off.

stdnum.id.nik.is_valid(number: str) → bool

  Check if the number is a valid Indonesian NIK.

stdnum.id.nik.validate(number: str) → str

  Check if the number is a valid Indonesian NIK.