API Reference¶
normalize Function¶
email_normalize.normalize(email_address, skip_dns=False)
¶
Normalize an email address.
This function abstracts the asyncio base for this library and
provides a blocking interface. If you intend to use this library
as part of an asyncio-based application, use
Normalizer.normalize instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email_address
|
str
|
The address to normalize. |
required |
skip_dns
|
bool
|
Skip DNS MX record lookups and use a static
domain map to detect well-known mailbox providers.
Defaults to |
False
|
Source code in email_normalize/__init__.py
Normalizer Class¶
email_normalize.Normalizer
¶
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.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name_servers
|
list[str] | None
|
Optional list of hostnames to use for DNS resolution. |
None
|
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 |
True
|
failure_ttl
|
int
|
Duration in seconds to cache DNS failures. Only
works when |
300
|
Source code in email_normalize/__init__.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 | |
mx_records(domain_part)
async
¶
Resolve MX records for a domain.
Returns a list of tuples with the MX priority and value.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain_part
|
str
|
The domain to resolve MX records for. |
required |
Source code in email_normalize/__init__.py
normalize(email_address)
async
¶
Normalize an email address.
Returns a Result containing the original address, the
normalized address, the MX records found, and the detected
mailbox provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email_address
|
str
|
The address to normalize. |
required |
Source code in email_normalize/__init__.py
Result Class¶
email_normalize.Result
dataclass
¶
Contains data from the email normalization process.
Attributes:
| Name | Type | Description |
|---|---|---|
address |
str
|
The address that was normalized. |
normalized_address |
str
|
The normalized version of the address. |
mx_records |
MXRecords
|
A list of tuples representing the priority and host of the MX records found for the email address. If empty, indicates a failure to lookup the domain part. |
mailbox_provider |
str | None
|
The mailbox provider name, or |
Source code in email_normalize/__init__.py
MXRecords Type¶
email_normalize.MXRecords = list[tuple[int, str]]
module-attribute
¶
A type alias for a list of tuples containing the priority and host name for each record returned during the MX lookup.
Example: