Normalizer Class¶
- class
email_normalize.
Normalizer
(name_servers=None, cache_limit=1024, cache_failures=True, failure_ttl=300)[source]¶ Class for normalizing an email address and resolving MX records.
Normalization is processed by splitting the local and domain parts of the email address and then performing DNS resolution for the MX records associated with the domain part of the address. The MX records are processed against a set of mailbox provider specific rules. If a match is found for the MX record hosts, the rules are applied to the email address.
This class implements a least frequent recently used cache that respects the DNS TTL returned when performing MX lookups. Data is cached at the module level.
Usage Example
async def normalize(email_address: str) -> email_normalize.Result: normalizer = email_normalize.Normalizer() return await normalizer.normalize('foo@bar.io')
- Parameters
name_servers (list(str) or None) – Optional list of hostnames to use for DNS resolution
cache_limit (
int
) – The maximum number of domain results that are cached. Defaults to 1024.cache_failures (
bool
) – Toggle the behavior of caching DNS resolution failures for a given domain. When enabled, failures will be cached for failure_ttl seconds. Defaults to True.failure_ttl (
int
) – Duration in seconds to cache DNS failures. Only works when cache_failures is set to True. Defaults to 300 seconds.cache_limit –
cache_failures –
failure_ttl –
- async
mx_records
(domain_part)[source]¶ Resolve MX records for a domain returning a list of tuples with the MX priority and value.