Skip to content

About

Return a normalized email-address stripping ISP specific behaviors

Topics

Resources

Contributing

Stars

38 stars

Watchers

2 watching

Forks

Repository files navigation

email-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).

Version Status Coverage License

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
Google x x* x†
Microsoft x
ProtonMail x
Rackspace x
Yahoo
Yandex x
Zoho x
  • Plus Addressing: Strips everything after + in the local part
  • Strip Periods: Removes . from the local part
  • Local Part as Hostname: Extracts the subdomain as the local part (Fastmail custom domains)
  • Domain Folding: Rewrites provider alias domains to a single canonical domain

* Google strips periods only for consumer Gmail addresses (gmail.com and googlemail.com). Google Workspace custom domains route through the same MX servers but treat periods as significant, so periods are preserved for them (plus addressing is still stripped).

† Some providers deliver one mailbox under several domain names. These alias domains are folded to a single canonical form so the same mailbox always normalizes to the same address: Google's googlemail.com → gmail.com, and Apple's me.com and mac.com → icloud.com. Domains that share a provider but are separate mailboxes (e.g. Microsoft's outlook.com/hotmail.com, or Yahoo's yahoo.com/aol.com) are intentionally left unchanged.

Documentation

Full documentation is available at gmr.github.io/email-normalize.

About

Return a normalized email-address stripping ISP specific behaviors

Topics

Resources

Contributing

Stars

38 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages