Registry / auth-security / email-validator

email-validator

JSON →
library2.3.0pypypi✓ verified 52d ago

A robust email address syntax and deliverability validation library. Current version is 2.3.0, released actively since mid-2021.

auth-securitycommunicationserialization
pip install email-validator
Install & Compatibility
Where this runs
tested against v2.3.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.925 runs
installs and imports cleanly · install 0.0s · import 0.492s · 21.3MB
glibc
py 3.103.925 runs
installs and imports cleanly · install 1.9s · import 0.473s · 22MB
19MB installed
● package 19MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

validate_email
from email_validator import validate_email
Ensure to import from the correct package name with a dash.

Quick example showing how to validate an email.

from email_validator import validate_email, EmailNotValidError try: validate_email('test@example.com') # Validate. except EmailNotValidError as e: print(str(e)) # Handle the error.
Debug
Known issues
breakingChanged package import from 'email_validator' to 'email-validator'.
fix
Use 'from email_validator import ...' instead of the old underscore version.
affects: 2.3.0
deprecatedUsing 'email' field on ValidatedEmail is deprecated.
fix
Use 'normalized' instead.
affects: >=2.1.0
breakingThe library reports that the domain does not accept email. This indicates a change in how email_validator interprets domain records (e.g., MX records, DMARC/SPF policies, or explicit no-email configurations), leading to stricter validation.
fix
Verify the domain's MX records and DMARC/SPF policies. If the domain example.com is expected to accept email, this suggests a stricter validation policy has been introduced in a newer email_validator version. Adjust test data or consult the library's changelog for specific behavior changes related to domain validation.
affects: >=2.2.0
gotchaEmail validation fails with 'The domain name example.com does not accept email.', indicating a change in how domain email acceptance is determined (e.g., changes in MX record checking or DNS resolution behavior).
fix
Verify the domain's MX records and other DNS settings. If using `email_validator`, investigate if its internal DNS lookup mechanism or the default settings for verifying email acceptance have changed in the current version, or if external DNS resolvers are causing issues.
affects: latest
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'email_validator'
The `email-validator` package is installed via `pip install email-validator`, but is typically imported using `from email_validator import validate_email` or similar. This error occurs if the package is not installed or if there's a typo in the import statement.
fix
Ensure the package is installed correctly using `pip install email-validator`. If already installed, verify the import statement is `from email_validator import validate_email, EmailNotValidError`.
email_validator.EmailNotValidError
This is the base exception raised by the `validate_email` function when an email address does not pass validation checks, which could be due to syntax issues, a non-existent domain, or other validation rules.
fix
Wrap calls to `validate_email()` in a `try...except EmailNotValidError as e:` block to gracefully handle invalid email addresses and access the human-readable error message `str(e)`.
email_validator.EmailUndeliverableError: The domain name ____ does not exist.
This specific `EmailNotValidError` subclass is raised when `validate_email` (with `check_deliverability=True`, which is the default) cannot find MX records for the domain, indicating the domain cannot receive email or does not exist.
fix
If deliverability checks are not required (e.g., for login forms or testing), call `validate_email(email, check_deliverability=False)`. Otherwise, the email address genuinely has an unresolvable domain.
RecursionError: maximum recursion depth exceeded
This error typically occurs when a user defines a function named `validate_email` in their own code, which then inadvertently calls itself recursively instead of the imported `email_validator.validate_email` function.
fix
Rename your local validation function to something distinct (e.g., `my_validate_email`) to avoid shadowing the imported `validate_email` function from the `email_validator` library.
Upgrade
Version history
2.3.0latest on PyPI
Audit
Dependencies

No dependency data recorded yet.

Agent activity
22 hits · last 30 days
node
8
mj12bot
4
ahrefsbot
3
seranking-bot
3
amazonbot
1
Resources