📬 emval
emval is a blazingly fast email validator written in Rust with Python bindings, offering performance improvements of 100-1000x over traditional validators.
Features
- Drop-in replacement for popular email validators like
python-email-validator,verify-email, andpyIsEmail. - 100-1000x faster than python-email-validator.
- Validates email address syntax according to RFC 5322 and RFC 6531.
- Checks domain deliverability (coming soon).
- Supports internationalized domain names (IDN) and local parts.
- Provides user-friendly syntax errors.
- Normalizes addresses.
- Rejects invalid and unsafe Unicode characters.
Getting Started
Install emval from PyPI:
or use emval in a Rust project:
Usage
Quick Start
To validate an email address in Python:
=
# Check if the email is valid.
=
# Utilize the normalized form for storage.
=
# Example: "Invalid Local Part: Quoting the local part before the '@' sign is not permitted in this context."
The same code in Rust:
use ;
Configurations
Customize email validation behavior using the EmailValidator class:
=
=
=
The same code in Rust:
use ;
Options
allow_smtputf8: Allows internationalized email addresses.allow_empty_local: Allows an empty local part (e.g.,@domain.com).allow_quoted_local: Allows quoted local parts (e.g.,"user name"@domain.com).allow_domain_literal: Allows domain literals (e.g.,[192.168.0.1]).deliverable_address: Checks if the email address is deliverable by verifying the domain's MX records.allowed_special_domains: List of special-use domains to allow despite being reserved (e.g.,['test', 'invalid']).
Polars Plugin
emval includes a high-performance Polars plugin for validating email addresses in DataFrames at scale.
Installation
The Polars plugin is included when you install emval:
Usage
Import the validate_email function from emval.polars and use it with Polars expressions:
# Create a DataFrame with email addresses
=
# Validate emails and add results as a struct column
=
# Extract individual fields from the validation result
=
Return Fields
The validate_email function returns a struct with the following fields:
original: The original email address (null if invalid)normalized: The normalized form of the email address (null if invalid)local_part: The local part of the email address (null if invalid)domain_address: The IP address if a domain literal was used (null otherwise)domain_name: The domain name (null if invalid)is_deliverable: Whether the email is deliverable based on MX records (null if invalid or not checked)
Invalid emails will have all fields set to null, making it easy to filter valid emails:
# Filter to only valid emails
=
Performance Benefits
The Polars plugin leverages Rust's performance and Polars' columnar architecture to validate millions of email addresses efficiently. This is ideal for:
- Data cleaning and validation pipelines
- Batch processing of user data
- ETL workflows
- Large-scale email list verification
Technical Details
Email Address Syntax
emval adheres to the syntax rules defined in RFC 5322 and RFC 6531. It supports both ASCII and internationalized characters.
Internationalized Email Addresses
Domain Names
emval converts non-ASCII domain names into their ASCII "Punycode" form according to IDNA 2008. This ensures compatibility with systems that do not support Unicode.
Local Parts
emval allows international characters in the local part of email addresses, following RFC 6531. It offers options to handle environments without SMTPUTF8 support.
Unsafe Unicode Characters
emval rejects unsafe Unicode characters to enhance security, preventing display and interpretation issues.
Normalization
emval normalizes email addresses to ensure consistency:
- Lowercasing domains: Domain names are standardized to lowercase.
- Unicode NFC normalization: Characters are transformed into their precomposed forms.
- Removing unnecessary characters: Quotes and backslashes in the local part are removed.
Acknowledgements
This project draws inspiration from python-email-validator. While python-email-validator is more comprehensive, emval aims to provide a faster solution.
Getting Help
For questions and issues, please open an issue in the GitHub issue tracker.
License
emval is licensed under the MIT License. See the LICENSE file for more details.