PhoneNumber API
digitz.PhoneNumber
dataclass
PhoneNumber(country_code: int, national_number: int, extension: Optional[str] = None, italian_leading_zero: bool = False, number_of_leading_zeros: Optional[int] = None, raw_input: Optional[str] = None, country_code_source: CountryCodeSource = CountryCodeSource.UNSPECIFIED, preferred_domestic_carrier_code: Optional[str] = None)
Bases: PhoneNumber
A dataclass representing a phone number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
country_code
|
int
|
The country code of the phone number. |
required |
national_number
|
int
|
The national number of the phone number. |
required |
extension
|
Optional[str]
|
The extension of the phone number. |
None
|
italian_leading_zero
|
bool
|
Whether the phone number has an Italian leading zero. |
False
|
number_of_leading_zeros
|
Optional[int]
|
The number of leading zeros in the phone number. |
None
|
raw_input
|
Optional[str]
|
The raw input of the phone number. |
None
|
country_code_source
|
CountryCodeSource
|
The source of the country code. |
UNSPECIFIED
|
preferred_domestic_carrier_code
|
Optional[str]
|
The preferred domestic |
None
|
Attributes
national_destination_code_length
cached
property
Returns the length of the national destination code.
national_significant_number
cached
property
Returns the national significant number.
national_destination_code
property
Returns the national destination code.
is_geographical
cached
property
Returns True if the phone number has a geographical association.
is_nanpa_country
cached
property
Returns True if the phone number is from a NANPA country.
is_fixed_line_or_mobile
property
Returns whether the phone number type is fixed line or mobile.
is_premium_rate
property
Returns whether the phone number type is premium rate.
is_personal_number
property
Returns whether the phone number type is personal number.
is_voicemail
property
Returns whether the phone number type is a voicemail access number.
timezones
cached
property
Returns the timezones of the phone number.
Functions
parse
classmethod
Attempts to parse a string and return a new PhoneNumber object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
number
|
str
|
The phone number to parse. |
required |
region
|
Optional[str]
|
The region code the phone number is expected to be from. |
None
|
keep_raw_input
|
bool
|
Whether to keep the raw input of the phone number. |
False
|
Raises:
| Type | Description |
|---|---|
NumberParseException
|
If the phone number cannot be parsed. |
Returns:
| Type | Description |
|---|---|
Self
|
A new PhoneNumber object. |
example_number
classmethod
example_number(region: str, number_type: PhoneNumberType = PhoneNumberType.FIXED_LINE) -> Optional[Self]
Returns an example phone number for the specified region and number type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str
|
The region code of the phone number. |
required |
number_type
|
PhoneNumberType
|
The type of phone number. |
FIXED_LINE
|
Returns:
| Type | Description |
|---|---|
Optional[Self]
|
An example phone number for the specified region and number type. |
match
Returns the match type of the phone number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other
|
Union[str, PhoneNumber]
|
The other phone number to compare. |
required |
Returns:
| Type | Description |
|---|---|
MatchType
|
The match type of the phone number. |
is_short_nsn_match
Returns True if the other phone number is a short NSN match.
is_nsn_match
Returns True if the other phone number is a NSN match.
is_exact_match
Returns True if the other phone number is an exact match.
is_any_nsn_match
Returns True if the other phone number is any NSN match.
is_any_match
Returns True if the other phone number is any match.
get_carrier_name
cached
Returns the carrier name of the phone number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lang
|
str
|
The language to use. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The carrier name of the phone number. |
get_country_name
cached
Returns the country name of the phone number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lang
|
str
|
The language to use. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The country name of the phone number. |
get_description
cached
Returns the description of the phone number.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lang
|
str
|
The language to use. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The description of the phone number. |
format
cached
Returns the string representation of the phone number in the specified format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
format
|
PhoneNumberFormat
|
The format to use. |
required |
Returns:
| Type | Description |
|---|---|
str
|
The string representation of the phone number. |
to_international
Returns the international representation of the phone number.
replace
replace(*, country_code: Union[int, _MISSING_TYPE] = MISSING, national_number: Union[int, _MISSING_TYPE] = MISSING, extension: Union[Optional[str], _MISSING_TYPE] = MISSING, italian_leading_zero: Union[bool, _MISSING_TYPE] = MISSING, number_of_leading_zeros: Union[Optional[int], _MISSING_TYPE] = MISSING) -> Self
Returns a new phone number with the specified attributes replaced.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
country_code
|
Union[int, _MISSING_TYPE]
|
The country code of the phone number. |
MISSING
|
national_number
|
Union[int, _MISSING_TYPE]
|
The national number of the phone number. |
MISSING
|
extension
|
Union[Optional[str], _MISSING_TYPE]
|
The extension of the phone number. |
MISSING
|
italian_leading_zero
|
Union[bool, _MISSING_TYPE]
|
Whether the phone number has an Italian leading zero. |
MISSING
|
number_of_leading_zeros
|
Union[Optional[int], _MISSING_TYPE]
|
The number of leading zeros in the phone number. |
MISSING
|
Returns:
| Type | Description |
|---|---|
Self
|
A new PhoneNumber object |