id-phonenumbers
raw JSON → 0.4.0 verified Fri May 01 auth: no python
Indonesian phone number parser and validator, based on Google's libphonenumber. Current version 0.4.0, with occasional releases. Parses, formats, and validates Indonesian mobile and fixed-line numbers, including area codes and operator prefixes.
pip install id-phonenumbers Common errors
error ModuleNotFoundError: No module named 'phonenumbers' ↓
cause Installed the wrong package (id-phonenumbers vs phonenumbers).
fix
Run
pip install id-phonenumbers and import as id_phonenumbers. error AttributeError: module 'id_phonenumbers' has no attribute 'parse' ↓
cause Incorrect import: using `import id_phonenumbers` then calling `id_phonenumbers.parse` but `parse` is a function directly in the module.
fix
Use
from id_phonenumbers import parse. error KeyError: 'ID' ↓
cause Passed an invalid region code or forgot to import PhoneNumberFormat constants.
fix
Use 'ID' as region code, and import PhoneNumberFormat if needed:
from id_phonenumbers import PhoneNumberFormat. Warnings
gotcha The import module is named `id_phonenumbers` (underscore, not hyphen). Many users mistakenly use `id-phonenumbers` as import name, which is invalid. ↓
fix Use `from id_phonenumbers import ...` in your code.
gotcha The parse function requires the second argument `region='ID'` to ensure Indonesian number parsing. Omitting it may lead to incorrect parsing for numbers without country code. ↓
fix Always pass `region='ID'` or `region=None` if number includes country code but better to be explicit.
deprecated Version 0.4.0 does not yet support Python 3.12+ officially (check setup.py). Using with Python 3.12+ may cause import errors due to removed APIs. ↓
fix Downgrade to Python 3.11 or use a virtual environment. Watch for updates.
Imports
- PhoneNumber wrong
from phonenumbers import PhoneNumbercorrectfrom id_phonenumbers import PhoneNumber - parse wrong
from phonenumbers import parsecorrectfrom id_phonenumbers import parse - is_valid_number wrong
from phonenumbers import is_valid_numbercorrectfrom id_phonenumbers import is_valid_number - format_number wrong
from phonenumbers import format_numbercorrectfrom id_phonenumbers import format_number - PhoneNumberFormat
from id_phonenumbers import PhoneNumberFormat
Quickstart
from id_phonenumbers import parse, is_valid_number, format_number, PhoneNumberFormat
number = '+6281234567890'
parsed = parse(number, 'ID')
print('Valid:', is_valid_number(parsed))
print('Formatted:', format_number(parsed, PhoneNumberFormat.INTERNATIONAL))