Skip to main content

A Python library for validating and suggesting corrections for email addresses.

Project description

Email Safeguard

A comprehensive email validation library that provides domain suggestions, disposable email detection, and MX record validation with a focus on security and user experience.

PyPI version Python Versions License: MIT

Features

  • 🔍 Smart validation with helpful suggestions
  • 🛡️ Disposable email detection
  • 📨 MX record validation
  • ⚡ Fast and customizable
  • 🎯 Type hints and modern Python support
  • 🔧 Configurable validation rules

Installation

pip install email-safeguard

Quick Start

from email_safeguard import EmailSafeguard

validator = EmailSafeguard()
result = validator.validate("user@gmial.com")

if result.is_valid:
    if result.suggestions:
        print(f"Email is valid but did you mean: {result.suggestions['domain']}?")
    else:
        print("Email is valid!")
else:
    print(f"Error: {result.message}")

Advanced Usage

Custom Configuration

validator = EmailSafeguard(
    check_mx=True,              # Enable MX record validation
    allow_disposable=False,     # Reject disposable emails
    suggest_corrections=True,   # Suggest corrections for typos
    max_distance=2             # Maximum edit distance for suggestions
)

Handling Results

from email_safeguard import EmailSafeguard, ValidationResult

validator = EmailSafeguard()
result = validator.validate("user@tempmail.com")

match result.result:
    case ValidationResult.VALID:
        print("Email is valid!")
    case ValidationResult.DISPOSABLE:
        print("Disposable emails not allowed")
    case ValidationResult.INVALID_DOMAIN:
        print(f"Invalid domain. Did you mean: {result.suggestions['domain']}?")
    case ValidationResult.NO_MX_RECORD:
        print("Domain has no mail server")

Data Files

The library uses three customizable data files:

  • popular_domains.txt: Common email domains
  • popular_tlds.txt: Valid top-level domains
  • disposable_domains.txt: Known disposable email providers

Custom Data Files

validator = EmailSafeguard(data_dir="path/to/data/directory")

Development

Running Tests

# Run all tests
python -m pytest

# Run with coverage
python -m pytest --cov=email_safeguard

Type Checking

mypy email_safeguard

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Chukwuka Ibejih (chukaibejih@gmail.com)

Acknowledgements

Built with:


If you find this library helpful, please give it a ⭐!

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

email_safeguard-0.1.3.tar.gz (968.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

email_safeguard-0.1.3-py3-none-any.whl (968.9 kB view details)

Uploaded Python 3

File details

Details for the file email_safeguard-0.1.3.tar.gz.

File metadata

  • Download URL: email_safeguard-0.1.3.tar.gz
  • Upload date:
  • Size: 968.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for email_safeguard-0.1.3.tar.gz
Algorithm Hash digest
SHA256 94ded8c633861113ddedb1de24a9fc2ca409c96f5700ae6ed623db72fcd7d1f2
MD5 fc5c8a58c1fea92022f3f13a6d64081a
BLAKE2b-256 ed3da118b48d3b964725d6451fc10e8b5b26496bf2373ccb64c8fe4596a61475

See more details on using hashes here.

File details

Details for the file email_safeguard-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for email_safeguard-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e46ae069a1b7701fb134787bd0c9dc7a4a3f630678a786e6ce36685b971a1fd9
MD5 a46bd98b7dd452acd91bb57b67cf8cb3
BLAKE2b-256 771e36aea3d84953cc19b922f611f8c467e603915ed94a24e9524ee307fdd64e

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