You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
In Development
2
2
--------------
3
3
4
+
* The library now includes an asynchronous version of the main method named validate_email_async, which can be called with await, that runs DNS-based deliverability checks asychronously.
4
5
* A new option to parse `My Name <address@domain>` strings, i.e. a display name plus an email address in angle brackets, is now available. It is off by default.
5
6
* When a domain name has no MX record but does have an A or AAAA record, if none of the IP addresses in the response are globally reachable (i.e. not Private-Use, Loopback, etc.), the response is treated as if there was no A/AAAA response and the email address will fail the deliverability check.
6
7
* When a domain name has no MX record but does have an A or AAAA record, the mx field in the object returned by validate_email incorrectly held the IP addresses rather than the domain itself.
internationalized local parts (like `ツ@example.com`),
22
23
and optionally parses display names (e.g. `"My Name" <me@example.com>`).
@@ -83,6 +84,9 @@ This validates the address and gives you its normalized form. You should
83
84
checking if an address is in your database. When using this in a login form,
84
85
set `check_deliverability` to `False` to avoid unnecessary DNS queries.
85
86
87
+
See below for examples for caching DNS queries and calling the library
88
+
asynchronously with `await`.
89
+
86
90
Usage
87
91
-----
88
92
@@ -163,6 +167,30 @@ while True:
163
167
validate_email(email, dns_resolver=resolver)
164
168
```
165
169
170
+
### Asynchronous call
171
+
172
+
The library has an alternative, asynchronous method named `validate_email_async` which must be called with `await`. This method uses an [asynchronous DNS resolver](https://dnspython.readthedocs.io/en/latest/async.html) so that multiple DNS-based deliverability checks can be performed in parallel.
173
+
174
+
Here how to use it. In this example, `import ... as` is used to alias the async method to the usual method name `validate_email`.
175
+
176
+
```python
177
+
from email_validator import validate_email_async as validate_email, \
178
+
EmailNotValidError, caching_async_resolver
179
+
180
+
resolver = caching_async_resolver(timeout=10)
181
+
182
+
email ="my+address@example.org"
183
+
try:
184
+
emailinfo =await validate_email(email)
185
+
email = emailinfo.normalized
186
+
except EmailNotValidError as e:
187
+
print(str(e))
188
+
```
189
+
190
+
Note that to create a caching asynchronous resolver, use `caching_async_resolver`. As with the synchronous version, creating a resolver is optional.
191
+
192
+
When processing batches of email addresses, I found that chunking around 25 email addresses at a time (using e.g. `asyncio.gather()`) resulted in the highest performance. I tested on a residential Internet connection with valid addresses.
193
+
166
194
### Test addresses
167
195
168
196
This library rejects email addresses that use the [Special Use Domain Names](https://www.iana.org/assignments/special-use-domain-names/special-use-domain-names.xhtml)`invalid`, `localhost`, `test`, and some others by raising `EmailSyntaxError`. This is to protect your system from abuse: You probably don't want a user to be able to cause an email to be sent to `localhost` (although they might be able to still do so via a malicious MX record). However, in your non-production test environments you may want to use `@test` or `@myname.test` email addresses. There are three ways you can allow this:
0 commit comments