External wrappers

A collection of phantom types that wraps functionality of well maintained implementations of third-party validation libraries. Importing from phantom.ext.* should be a hint that more dependencies need to be installed.

Phone numbers

Requires the phonenumbers package which can be installed with:

$ python3 -m pip install phantom-types[phonenumbers]

Types

class phantom.ext.phonenumbers.PhoneNumber(instance)[source]

Bases: str, phantom._base.Phantom

class phantom.ext.phonenumbers.FormattedPhoneNumber(instance)[source]

Bases: phantom.ext.phonenumbers.PhoneNumber

classmethod parse(instance)[source]

Normalize number using phonenumbers.PhoneNumberFormat.E164.

Raises

InvalidPhoneNumber

Parameters

instance (object) –

Return type

phantom.ext.phonenumbers.FormattedPhoneNumber

Functions

phantom.ext.phonenumbers.is_phone_number(phone_number, country_code=None)
Parameters
  • phone_number (str) –

  • country_code (str | None) –

Return type

phonenumbers.PhoneNumber

phantom.ext.phonenumbers.is_formatted_phone_number(number)[source]
Parameters

number (str) –

Return type

bool

phantom.ext.phonenumbers.normalize_phone_number(phone_number, country_code=None)[source]

Normalize phone_number using phonenumbers.PhoneNumberFormat.E164.

Raises

InvalidPhoneNumber

Parameters
  • phone_number (str) –

  • country_code (str | None) –

Return type

FormattedPhoneNumber

Exceptions

exception phantom.ext.phonenumbers.InvalidPhoneNumber(error_type=99, msg='Invalid number')[source]

Bases: phonenumbers.phonenumberutil.NumberParseException, TypeError

Parameters
  • error_type (int) –

  • msg (str) –