Skip to main content

Email validation with syntax checking and normalization.

Project description

philiprehberger-email-validate

Tests PyPI version GitHub release Last updated License Bug Reports Feature Requests Sponsor

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"})

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
results = validate_many(emails, check_mx=True, concurrent=True)

API

Function / Class Description
EmailResult Dataclass with valid, normalized, domain, error, and is_disposable 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) Full validation returning an EmailResult
validate_many(emails, check_mx, concurrent, extra_disposable) Validate multiple emails with optional parallel MX lookups
set_disposable_domains(domains) Merge additional domains into the global disposable domains set
DISPOSABLE_DOMAINS Mutable set of known disposable email domains

Development

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

Support

If you find this package useful, consider giving it a star on GitHub — it helps motivate continued maintenance and development.

LinkedIn More packages

License

MIT

Project details


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.3.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

File details

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

File metadata

File hashes

Hashes for philiprehberger_email_validate-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9f6c6913280591ae7ed757df9ef17327e4d1474082c43bb55f216458d2b7910b
MD5 ab0e56b3c425f5b8b7ba328cfe1d3af5
BLAKE2b-256 e38cce16570d208d851639d6cc93672e0b70961ea7a06a555ab23ea4d73b5a96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_email_validate-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6010dbf379abe505fc753b16d4444350c1a363e990f235deccaecf07a583449e
MD5 4866eeaddd59d8e27538f2179ccf5834
BLAKE2b-256 9776baedacf8b7b4cd38b0d7914495cdf02c453df85c427358e36d91f1d4fb9b

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 Pingdom Monitoring Sentry Error logging StatusPage Status page