Example usage
Here we will demonstrate how to use nomiden
Checking package version
[1]:
import nomiden
nomiden.__version__
[1]:
'0.0.7'
To use nomiden in a project
[2]:
from nomiden import reader as nr
Retreive NIK (Nomor Induk Kependudukan) information
First you will need to make a NIK object by passing the NIK number as an input parameter. NIK number can have the type str or int.
[3]:
# int NIK number
id_nik = nr.NIK(1111111111111111)
# str NIK number
id_nik = nr.NIK("1111111111111111")
Next, you can retreive individual informations by calling its attributes.
[4]:
# Get province
id_nik.province
[4]:
'ACEH'
[5]:
# Get city
id_nik.city
[5]:
'KAB. BIREUEN'
[6]:
# Get district
id_nik.district
[6]:
'Simpang Mamplam'
[7]:
# Get gender
id_nik.gender
[7]:
'Male'
[8]:
# Get birth date (date of the month)
id_nik.birthdate
[8]:
11
[9]:
# Get birth month
id_nik.birthmonth
[9]:
11
[10]:
# Get birth year
id_nik.birthyear
[10]:
2011
[11]:
# Get birth datetime
id_nik.birthdtm
[11]:
datetime.datetime(2011, 11, 11, 0, 0)
[12]:
# Get complete birthday as a string
id_nik.birthday
[12]:
'11 November 2011'
[13]:
# Get age
id_nik.age
[13]:
12
[14]:
# Get registration code
id_nik.nth_person
[14]:
111
Or you can also get all informations as a dictionary
[15]:
# Get all informations
id_nik.all_info
[15]:
{'NIK': 1111111111111111,
'province': 'ACEH',
'city': 'KAB. BIREUEN',
'district': 'Simpang Mamplam',
'gender': 'Male',
'birth_datetime': datetime.datetime(2011, 11, 11, 0, 0),
'birthday': '11 November 2011',
'age': 12,
'regist_code': 111}
Retreive KK (Kartu Keluarga) information
Similar to NIK, you will need to make a KK object by passing the KK number as an input parameter. KK number can have the type str or int.
[16]:
# int NIK number
id_kk = nr.KK(1111111111111111)
# str NIK number
id_kk = nr.KK("1111111111111111")
Next, you can retreive individual informations by calling its attributes.
Note: KK number does not contain gender and age information, since it is a family ID number, not a personal one. KK also does not contain any birth information, but it does contain registration informations.
[17]:
# Get province
id_kk.province
[17]:
'ACEH'
[18]:
# Get city
id_kk.city
[18]:
'KAB. BIREUEN'
[19]:
# Get district
id_kk.district
[19]:
'Simpang Mamplam'
[20]:
# Get registration date (date of the month)
id_kk.regdate
[20]:
11
[21]:
# Get registration month
id_kk.regmonth
[21]:
11
[22]:
# Get registration year
id_kk.regyear
[22]:
2011
[23]:
# Get registration datetime
id_kk.regdtm
[23]:
datetime.datetime(2011, 11, 11, 0, 0)
[24]:
# Get complete registration day as a string
id_kk.regday
[24]:
'11 November 2011'
[25]:
# Get registration code
id_kk.nth_pub
[25]:
111
Or you can also get all informations as a dictionary
[26]:
# Get all informations
id_kk.all_info
[26]:
{'NIK': 1111111111111111,
'province': 'ACEH',
'city': 'KAB. BIREUEN',
'district': 'Simpang Mamplam',
'regist_datetime': datetime.datetime(2011, 11, 11, 0, 0),
'regist_day': '11 November 2011',
'regist_code': 111}
Usage for Pandas Series input
If you have a Series of IDs you would like to retrieve information from, you can use Pandas’ .apply() method along with lambda function.
[27]:
import pandas as pd
# Make a dummy DataFrame
nik_list = ["1111111111111111", "1111111111111112"]
df = pd.DataFrame({'id_nik': nik_list})
# Get province and save it to a new column
df['prov'] = df['id_nik'].apply(lambda x: nr.NIK(x).province)
df
[27]:
| id_nik | prov | |
|---|---|---|
| 0 | 1111111111111111 | ACEH |
| 1 | 1111111111111112 | ACEH |
Making a DataFrame from a Series input
Since .all_info attribute returns a dictionary, you can convert it into Pandas DataFrame.
[28]:
df_allinfo = pd.DataFrame(df['id_nik'].apply(lambda x: nr.NIK(x).all_info).tolist())
df_allinfo
[28]:
| NIK | province | city | district | gender | birth_datetime | birthday | age | regist_code | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 1111111111111111 | ACEH | KAB. BIREUEN | Simpang Mamplam | Male | 2011-11-11 | 11 November 2011 | 12 | 111 |
| 1 | 1111111111111112 | ACEH | KAB. BIREUEN | Simpang Mamplam | Male | 2011-11-11 | 11 November 2011 | 12 | 112 |