Crates.io | emval |
lib.rs | emval |
version | |
source | src |
created_at | 2024-12-05 16:56:41.960294 |
updated_at | 2024-12-05 17:07:46.026049 |
description | emval is a blazingly fast email validator |
homepage | https://github.com/bnkc/emval |
repository | https://github.com/bnkc/emval |
max_upload_size | |
id | 1473396 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
emval
is a blazingly fast email validator written in Rust with Python bindings, offering performance improvements of 100-1000x over traditional validators.
python-email-validator
, verify-email
, and pyIsEmail
.Install emval
from PyPI:
pip install emval
or use emval
in a Rust project:
cargo add emval
To validate an email address in Python:
from emval import validate_email, EmailValidator
email = "example@domain.com"
try:
# Check if the email is valid.
val_email = validate_email(email)
# Utilize the normalized form for storage.
normalized_email = val_email.normalized
except Exception as e:
# Example: "Invalid Local Part: Quoting the local part before the '@' sign is not permitted in this context."
print(str(e))
The same code in Rust:
use emval::{validate_email, ValidationError};
fn main() -> Result<(), ValidationError> {
let email = "example@domain.com";
let val_email = validate_email(email)?;
let normalized_email = val_email.normalized;
Ok(())
}
Customize email validation behavior using the EmailValidator
class:
from emval import EmailValidator
emval = EmailValidator(
allow_smtputf8=False,
allow_empty_local=True,
allow_quoted_local=True,
allow_domain_literal=True,
deliverable_address=False,
)
email = "user@[192.168.1.1]"
try:
validated_email = emval.validate_email(email)
print(validated_email)
except Exception as e:
print(str(e))
The same code in Rust:
use emval::{EmailValidator, ValidationError};
fn main() -> Result<(), ValidationError> {
let emval = EmailValidator {
allow_smtputf8: false,
allow_empty_local: true,
allow_quoted_local: true,
allow_domain_literal: true,
deliverable_address: false,
};
let email = "example@domain.com";
let validated_email = emval.validate_email(email)?;
Ok(())
}
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.emval adheres to the syntax rules defined in RFC 5322 and RFC 6531. It supports both ASCII and internationalized characters.
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.
emval allows international characters in the local part of email addresses, following RFC 6531. It offers options to handle environments without SMTPUTF8 support.
emval rejects unsafe Unicode characters to enhance security, preventing display and interpretation issues.
emval normalizes email addresses to ensure consistency:
This project draws inspiration from python-email-validator. While python-email-validator
is more comprehensive, emval
aims to provide a faster solution.
For questions and issues, please open an issue in the GitHub issue tracker.
emval is licensed under the MIT License. See the LICENSE file for more details.