Skip to main content

philiprehberger-email-validate

Tests PyPI version Last updated

philiprehberger-email-validate

Email validation with syntax checking and normalization.

Installation

pip install philiprehberger-email-validate

Usage

from philiprehberger_email_validate import validate_email

result = validate_email("user@example.com")
print(result.valid)       # True
print(result.normalized)  # "user@example.com"
print(result.domain)      # "example.com"

Quick Syntax Check

from philiprehberger_email_validate import is_valid

is_valid("user@example.com")   # True
is_valid("not-an-email")       # False

Normalization

from philiprehberger_email_validate import normalize

normalize("  User@Example.COM  ")          # "user@example.com"
normalize("first.last+tag@gmail.com")      # "firstlast@gmail.com"
normalize("user+promo@example.com")        # "user@example.com"

MX Lookup

from philiprehberger_email_validate import validate_email

result = validate_email("user@example.com", check_mx=True)
if not result.valid:
    print(result.error)  # "MX lookup failed for domain: example.com"

Disposable Email Detection

from philiprehberger_email_validate import validate_email

result = validate_email("user@mailinator.com")
print(result.is_disposable)  # True

Custom Disposable Domains

from philiprehberger_email_validate import validate_email, set_disposable_domains

# Per-call extra domains
result = validate_email("user@tempmail.xyz", extra_disposable=["tempmail.xyz"])
print(result.is_disposable)  # True

# Global merge with built-in list
set_disposable_domains({"tempmail.xyz", "fakeemail.org"})

Role-Based Email Detection

from philiprehberger_email_validate import validate_email, is_role_based

result = validate_email("info@example.com")
print(result.is_role_based)  # True

is_role_based("admin@example.com")    # True
is_role_based("john@example.com")     # False

Free Provider Detection

Flag consumer/free mailboxes (useful for filtering B2B signups that should use a company address):

from philiprehberger_email_validate import validate_email, is_free_email

result = validate_email("user@gmail.com")
print(result.is_free)  # True

is_free_email("user@gmail.com")        # True
is_free_email("user@acme-corp.com")    # False

Email Domain Suggestions

from philiprehberger_email_validate import validate_email, suggest_domain, suggest_email

result = validate_email("user@gmial.com")
print(result.suggested_domain)  # "gmail.com"

suggest_domain("hotmial.com")   # "hotmail.com"
suggest_domain("gmail.com")     # "" (no suggestion needed)

# Correct the whole address (local part and any +tag are preserved)
suggest_email("first.last+promo@hotmial.com")  # "first.last+promo@hotmail.com"
suggest_email("user@gmail.com")                # "" (no suggestion needed)

RFC 5321 Strict Mode

from philiprehberger_email_validate import validate_email

result = validate_email("user@example.com", strict=True)
print(result.valid)  # True

result = validate_email(".user@example.com", strict=True)
print(result.valid)  # False
print(result.error)  # "Local part starts or ends with a dot (RFC 5321)"

Bulk Validation

from philiprehberger_email_validate import validate_many

results = validate_many(["user@example.com", "bad@@email", "test@gmail.com"])
for r in results:
    print(r.normalized, r.valid)

# With concurrent MX lookups and strict mode
results = validate_many(emails, check_mx=True, concurrent=True, strict=True)

Extract Emails from Text

from philiprehberger_email_validate import extract_emails

emails = extract_emails("Contact hello@example.com or support@test.org")
# ["hello@example.com", "support@test.org"]

Email Parts

from philiprehberger_email_validate import email_parts

parts = email_parts("user@example.com")
print(parts.local)   # "user"
print(parts.domain)  # "example.com"
print(parts.tld)     # "com"

Mask Email

from philiprehberger_email_validate import mask_email

mask_email("john@example.com")     # "j***n@example.com"
mask_email("alice@example.com")    # "a***e@example.com"

Disposable check

from philiprehberger_email_validate import is_disposable

is_disposable("user@mailinator.com")   # True
is_disposable("user@gmail.com")        # False
is_disposable("not-an-email")          # False

Comparing emails

from philiprehberger_email_validate import compare_emails

compare_emails("Foo@Gmail.com", "foo@gmail.com")              # True
compare_emails("foo.bar+tag@gmail.com", "foobar@gmail.com")   # True
compare_emails("foo@a.com", "bar@a.com")                      # False

API

Function / Class Description
EmailResult Dataclass with valid, normalized, domain, error, is_disposable, is_role_based, is_free, and suggested_domain fields
normalize(email) Normalize an email: lowercase, strip whitespace, Gmail dot-insensitivity, plus-addressing cleanup
is_valid(email) Quick boolean syntax check
validate_email(email, check_mx, extra_disposable, strict) Full validation returning an EmailResult
validate_many(emails, check_mx, concurrent, extra_disposable, strict) Validate multiple emails with optional parallel MX lookups
is_role_based(email) Check if an email uses a role-based local part (info@, admin@, etc.)
is_disposable(email) Check if an email's domain is in the disposable-domains set
is_free_email(email) Check if an email's domain is a known free/public provider (gmail, yahoo, etc.)
compare_emails(a, b) Check if two emails are equivalent after normalization
suggest_domain(domain) Suggest a corrected domain for common typos
suggest_email(email) Suggest a corrected full email address for a domain typo
set_disposable_domains(domains) Merge additional domains into the global disposable domains set
DISPOSABLE_DOMAINS Mutable set of known disposable email domains
ROLE_PREFIXES Frozen set of known role-based email prefixes
COMMON_DOMAINS Frozen set of common email provider domains used for suggestions
FREE_EMAIL_DOMAINS Frozen set of known free/public email provider domains
extract_emails(text) Extract all valid email addresses from text, deduplicated
email_parts(email) Split email into structured parts (local, domain, tld, normalized)
EmailParts Dataclass with local, domain, tld, normalized fields
mask_email(email, mask_char, visible) Mask the local part for privacy display

Development

pip install -e .
python -m pytest tests/ -v

Support

If you find this project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

philiprehberger_email_validate-0.7.0.tar.gz (188.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

philiprehberger_email_validate-0.7.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file philiprehberger_email_validate-0.7.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_email_validate-0.7.0.tar.gz
Algorithm Hash digest
SHA256 b848f6e926102ea6b3b7dc3578c2d189b8bcefdd4a679ffc911ab77ee71bef4e
MD5 baf57f1de4bd51ee8c5071fdcece3e63
BLAKE2b-256 53fba6d8a497a2d7547d3d6a47203ce503fedecc4f859184c3a393f9d05562ec

See more details on using hashes here.

File details

Details for the file philiprehberger_email_validate-0.7.0-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_email_validate-0.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24620c64fb7f974dbc23d90cb9b778837e782ee7fe445a74dc3b96ffc92683a5
MD5 3c195972a8b7ec36bd3282614084b2d8
BLAKE2b-256 e53fb07d88fc26e6e3188973345e3418b339820119c01efb75c12f0af2638594

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page