apeye.email_validator


Email address validation functions.

New in version 1.0.0.

This module is a subset of https://pypi.org/project/email-validator

Note

The classes in this module can instead be imported from the apeye_core.email_validator module instead.

Exceptions:

EmailSyntaxError

Exception raised when an email address fails validation because of its form.

Classes:

ValidatedEmail(original_email, email, …[, …])

Represents the return type of the validate_email() function.

Functions:

validate_email(email[, allow_smtputf8, …])

Validates an email address.

validate_email_domain_part(domain)

Validate the domain part of an email address (the part after the @-sign).

validate_email_local_part(local[, …])

Validates the local part of an email address (the part before the @-sign).

exception EmailSyntaxError[source]

Bases: ValueError

Exception raised when an email address fails validation because of its form.

class ValidatedEmail(original_email, email, local_part, domain, *, ascii_email=None, ascii_local_part=None, ascii_domain=None, smtputf8=None)

Bases: object

Represents the return type of the validate_email() function.

This class holds the normalized form of the email address alongside other information.

Parameters
  • original_email (str) – The original, unnormalized email address.

  • email (str) – The normalized email address, which should always be used in preference to the original address.

  • local_part (str) – The local part of the email address after Unicode normalization.

  • domain (str) – The domain part of the email address after Unicode normalization or conversion to Unicode from IDNA ascii.

  • ascii_email (Optional[str]) – If not None, a form of the email address that uses 7-bit ASCII characters only. Default None.

  • ascii_local_part (Optional[str]) – If not None, the local part of the email address using 7-bit ASCII characters only. Default None.

  • ascii_domain (Optional[str]) – If not None, a form of the domain name that uses 7-bit ASCII characters only. Default None.

  • smtputf8 (Optional[bool]) – Indicates whether SMTPUTF8 will be required to transmit messages to this address. Default None.

Methods:

__eq__(other)

Return self == other.

__repr__()

Return a string representation of the ValidatedEmail object.

__str__()

Return a string representation of the ValidatedEmail object.

as_dict()

Convenience method for accessing the ValidatedEmail as a dict.

__eq__(other)[source]

Return self == other.

Return type

bool

__repr__()[source]

Return a string representation of the ValidatedEmail object.

Return type

str

__str__()[source]

Return a string representation of the ValidatedEmail object.

Return type

str

as_dict()[source]

Convenience method for accessing the ValidatedEmail as a dict.

Return type

Dict[str, Any]

validate_email(email, allow_smtputf8=True, allow_empty_local=False)[source]

Validates an email address.

Parameters
  • email (Union[str, bytes]) – Either a string, or ASCII-encoded bytes.

  • allow_smtputf8 (bool) – Default True.

  • allow_empty_local (bool) – Whether to allow the local part (the bit before the @-sign) to be empty. Default False.

Raises

EmailSyntaxError – if the address is not valid

Return type

ValidatedEmail

validate_email_domain_part(domain)[source]

Validate the domain part of an email address (the part after the @-sign).

Parameters

domain (str)

Return type

Dict[str, str]

validate_email_local_part(local, allow_smtputf8=True, allow_empty_local=False)[source]

Validates the local part of an email address (the part before the @-sign).

Parameters
  • local (str)

  • allow_smtputf8 (bool) – Default True.

  • allow_empty_local (bool) – Whether to allow the local part to be empty/. Default False.

Return type

Dict[str, Any]