Skip to main content

Email validation with syntax checking and normalization.

Project description

philiprehberger-email-validate

Tests PyPI version Last updated

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 project useful:

Star the repo

🐛 Report issues

💡 Suggest features

❤️ Sponsor development

🌐 All Open Source Projects

💻 GitHub Profile

🔗 LinkedIn Profile

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.1.tar.gz (7.3 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.1.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_email_validate-0.3.1.tar.gz
Algorithm Hash digest
SHA256 6018f14ef84afb3da35d0ba2e765c90a9577945c7c8593e1069aff16c5f191dc
MD5 5249aaa8064758d4f010695d4cc862e2
BLAKE2b-256 88c87c8b07a1bda0636e536fc59ade3d27560579e6eafe75ee03baba514ec9c2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_email_validate-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3c84b79365459a9f6f741fc1931be985e80435f887e7bcc20405c75251a57a17
MD5 1cd2aa1747cbc57d9d023c5b9a6b4f9c
BLAKE2b-256 e13d5ad1fa1c0c7de03aaf65b6ed55fb6b88059d3cd9bdec3d3a6ddddcb04665

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