Skip to main content Switch to mobile version lokal-id 0.18.3 Indonesian data primitives for apps and AI agents: NIK, NPWP, phone numbers, Rupiah, terbilang, holidays, Kemendagri regions with postal codes, and Samaran PII masking (UU PDP).
pip install lokal-id==0.18.3 Copy PIP instructions
Indonesian data primitives for Python backends and AI agents: NIK, NPWP, phone numbers, Rupiah, terbilang, holidays and working days, Kemendagri regions with postal codes, and Samaran, which masks Indonesian personal data before it reaches an LLM or a log, and restores it afterwards.
The Python port of @lokal-id/core: same rules, same data, same results, checked by replaying thousands of TypeScript outputs in the test suite. No dependencies, fully typed, Python 3.10+.
Part of Lokal · Bahasa Indonesia
pip install lokal-id import lokal # NIK, NPWP, phone, Rupiah, holidays, Samaran from lokal import wilayah # regions and postal codes (loaded on first use) Usage
from decimal import Decimal import datetime as dt from lokal import ( parse_nik, parse_npwp, parse_phone, format_rupiah, format_rupiah_short, parse_rupiah, terbilang, add_working_days, is_working_day, ) from lokal.wilayah import list_wilayah, search_wilayah, wilayah_name, find_by_postal_code, parse_alamat nik = parse_nik('3201011508950001', lookup_wilayah=wilayah_name) nik.valid, nik.regency, nik.district, nik.gender, nik.birth_date # (True, 'Kabupaten Bogor', 'Cibinong', 'L', '1995-08-15') phone = parse_phone('0812 3456 7890') phone.e164, phone.national, phone.whatsapp, phone.operator # ('+6281234567890', '0812-3456-7890', '6281234567890', 'Telkomsel') format_rupiah(1500000) # 'Rp1.500.000' format_rupiah(Decimal('1500000.505'), decimals=True) # 'Rp1.500.000,51', exact for database decimals format_rupiah_short(2300000000) # 'Rp2,3 M' terbilang(1500000, currency=True) # 'satu juta lima ratus ribu rupiah' parse_rupiah('2jtan') # ParsedRupiah(amount=2000000, approximate=True) parse_rupiah('sejuta setengah') # ParsedRupiah(amount=1500000, approximate=False) add_working_days('2026-03-17', 1) # '2026-03-25', skipping Nyepi and Lebaran add_working_days(dt.date(2026, 3, 17), 1) # datetime.date(2026, 3, 25): dates in, dates out is_working_day('2026-12-24', cuti_bersama=False) # True for offices that ignore cuti bersama len(list_wilayah('32.76')) # 11 kecamatan in Kota Depok search_wilayah('kab. bogor')[0].code # '32.01' find_by_postal_code('16431')[0].path # 'Depok, Pancoran Mas, Kota Depok, Jawa Barat' alamat = parse_alamat('jl margonda raya no 100 rt 3/5 kemiri muka beji depok 16423') alamat.kelurahan_desa.code, alamat.rt, alamat.confidence # ('32.76.06.1004', '003', 'high') Every result is a dataclass. to_dict() gives a JSON-ready dict without empty fields, and to_dict(camel=True) uses the same keys as the TypeScript package (birthDate, postalCode) for frontends that share types with it.
Samaran: mask before the LLM, restore after
from anthropic import Anthropic from lokal import Samaran client = Anthropic() def balas_pelanggan(pesan: str) -> str: samaran = Samaran() # one vault per conversation or request masked = samaran.mask(pesan).text # 'NIK saya [NIK_1], HP [PHONE_1]' reply = client.messages.create( model='claude-sonnet-5-5', max_tokens=1024, messages=[{'role': 'user', 'content': masked}], ) return samaran.unmask(reply.content[0].text) # real values back, on your server The same value always maps to the same placeholder, across formats: 0812-… and +62 812… are both [PHONE_1].
Samaran(mode='partial') is for logs and admin screens: 3201********0001, 0812****7890, b***@gmail.com.
Samaran(exclude=['FINANCIAL', 'NAME']) keeps types your app has to read, such as income and installments in a dealer's credit simulation, while NIK, phone numbers, and accounts are still masked. types= does the opposite (only those). An unknown type name raises ValueError.
Samaran(allow=['cs@toko.id', re.compile(r'@toko\.id











