Return a normalized email-address stripping ISP specific behaviors
Maintained. Last release 4 months ago, commits in 4 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install email-normalizeemail-normalize
A Python 3.11+ library for normalizing email addresses by stripping
mailbox-provider-specific behaviors such as plus addressing
(foo+bar@gmail.com) and period ignoring (f.o.o@gmail.com).
Installation
pip install email-normalize
Usage
Synchronous
import email_normalize
result = email_normalize.normalize('f.o.o+bar@gmail.com')
print(result.normalized_address) # foo@gmail.com
print(result.mailbox_provider) # Google
print(result.mx_records) # [(5, 'gmail-smtp-in.l.google.com'), ...]
Async
For use within an asyncio application, use the Normalizer class directly:
import asyncio
import email_normalize
async def main():
normalizer = email_normalize.Normalizer()
result = await normalizer.normalize('f.o.o+bar@gmail.com')
print(result.normalized_address)
asyncio.run(main())
The Normalizer maintains a LFRU cache of MX lookups, making it efficient
for batch processing.
Without DNS Lookups
Use skip_dns=True to normalize against well-known domains without
performing MX record lookups:
result = email_normalize.normalize('user+tag@gmail.com', skip_dns=True)
This mode uses a static domain map and will not detect providers for custom domains.
Normalization Rules
| Provider | Plus Addressing | Strip Periods | Local Part as Hostname | Domain Folding |
|---|---|---|---|---|
| Apple | x | x† | ||
| Fastmail | x | x | ||