Email validation with syntax checking and normalization.
Project description
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"})
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:
License
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file philiprehberger_email_validate-0.3.1.tar.gz.
File metadata
- Download URL: philiprehberger_email_validate-0.3.1.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6018f14ef84afb3da35d0ba2e765c90a9577945c7c8593e1069aff16c5f191dc
|
|
| MD5 |
5249aaa8064758d4f010695d4cc862e2
|
|
| BLAKE2b-256 |
88c87c8b07a1bda0636e536fc59ade3d27560579e6eafe75ee03baba514ec9c2
|
File details
Details for the file philiprehberger_email_validate-0.3.1-py3-none-any.whl.
File metadata
- Download URL: philiprehberger_email_validate-0.3.1-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3c84b79365459a9f6f741fc1931be985e80435f887e7bcc20405c75251a57a17
|
|
| MD5 |
1cd2aa1747cbc57d9d023c5b9a6b4f9c
|
|
| BLAKE2b-256 |
e13d5ad1fa1c0c7de03aaf65b6ed55fb6b88059d3cd9bdec3d3a6ddddcb04665
|