Skip to main content

A lightweight, type-safe email validator with support of multiple validator.

Project description

🛡️ univalidator

PyPI version Python versions License

A flexible, extensible, and type-safe Python validation framework designed to validate data with ease.
Currently supports email validation (via regex and MX records) and composite validators for running multiple checks.

✨ Features

  • Abstract Validator Interface — define your own validators easily.
  • Regex-based Validation — for any string patterns.
  • Email Format Validation — RFC-compliant pattern check.
  • MX Record Validation — verifies if an email domain can receive emails.
  • Composite Validation — run multiple validators in sequence.
  • Type Safe — written with modern Python type hints.

📦 Installation

  • By using uv:

    uv add univalidator
    
  • By using pip:

    pip install univalidator
    

📚 API Reference

1️ BaseValidator[T]

Abstract base for all validators. Custom validators must implement the validate(data: T) -> bool method.

2️ RegexValidator[T]

Validates data against a regular expression.

from univalidator.validators import RegexValidator

validator = RegexValidator[str](r"^\d{4}-\d{2}-\d{2}$")  # YYYY-MM-DD format
validator.validate("2025-08-15")  # True
validator.validate("15-08-2025")  # False

3️ RegexEmailValidator[T]

Validates email format using a regex pattern. Uses a default pattern, but you can pass your own.

from univalidator.validators import RegexEmailValidator

validator = RegexEmailValidator[str]()
validator.validate("user@example.com")  # True
validator.validate("invalid-email")     # False

4️ MXEmailRecordValidator[T]

Checks if an email’s domain has MX DNS records.

from univalidator.validators import MXEmailRecordValidator

validator = MXEmailRecordValidator[str]()
validator.validate("user@gmail.com")  # True
validator.validate("user@no-such-domain.com")  # False

Restrict to specific domains:

validator = MXEmailRecordValidator[str](allowed_domains=["example.com", "gmail.com"])

5️ CompositeValidator[T]

Runs multiple validators in sequence. All validators must pass for the data to be valid.

from univalidator.composites import CompositeValidator
from univalidator.validators import RegexEmailValidator, MXEmailRecordValidator

validator = CompositeValidator[str]([
    RegexEmailValidator(),
    MXEmailRecordValidator()
])

validator.validate("user@gmail.com")  # True

🧪 Testing

uv add pytest
uv run pytest tests

🌟 Example: Full Email Validation

from univalidator.composites import CompositeValidator
from univalidator.validators import RegexEmailValidator, MXEmailRecordValidator

validator = CompositeValidator[str]([
    RegexEmailValidator(),
    MXEmailRecordValidator()
])

email = "test@gmail.com"
if validator.validate(email):
    print("Valid email with active domain!")
else:
    print("Invalid email.")

🛠️ Planned Features

  • 🔒 Add more Validators

🤝 Contributing

Contributions are welcome! Please open an issue or PR for any improvements.

📜 License

MIT License — See LICENSE.

👤 Author

For questions or assistance, contact Shailesh at shaileshpandit141@gmail.com.

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

univalidator-0.2.0.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

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

univalidator-0.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

Details for the file univalidator-0.2.0.tar.gz.

File metadata

  • Download URL: univalidator-0.2.0.tar.gz
  • Upload date:
  • Size: 13.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.6

File hashes

Hashes for univalidator-0.2.0.tar.gz
Algorithm Hash digest
SHA256 7adaf159789d20c692d0c7317b2ce30cfa09e85ba68056d6245d654c0ac6b2a4
MD5 20564475c7a0297b2a3d266d971ecdea
BLAKE2b-256 c94d3ab10d636d862bb4db5900e3f1d0ad189af041843f086c96825208f91963

See more details on using hashes here.

File details

Details for the file univalidator-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for univalidator-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d24817acc077d0e99e665033a545b2c227ea108f0ed63612aabc7d6fac4e439e
MD5 b6af707eeef981612e52021598c9bb27
BLAKE2b-256 0374a9a2c5380cfdd5c5f9d407abea5e4bd2d7054da95fdd7e79ab1a69abd3a3

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