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-2.0.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

univalidator-2.0.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: univalidator-2.0.0.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for univalidator-2.0.0.tar.gz
Algorithm Hash digest
SHA256 c9c64b86cae56139c24ce324486f84f2353c8f1fe4a47ceb0ee16fa29570b961
MD5 99593f6cd50c339835b0138800ba1a2c
BLAKE2b-256 b7c50bd51baf4f44d964dc4de82f5b165428cc7980826a8c42d39ce3e2c63ac6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: univalidator-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.25 {"installer":{"name":"uv","version":"0.9.25","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for univalidator-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 91bd53e1594107f6ad840bcc15a0e3a5c02d05307155319672529232a4a603a2
MD5 d8508afbb4fcdf04111666de0b4664f8
BLAKE2b-256 0b0a822ec344c7fab37709e099c786fd066e9dacca884c0930c0dd4a9742c5bf

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