univalidator


Nameunivalidator JSON
Version 0.2.1 PyPI version JSON
download
home_pageNone
SummaryA lightweight, type-safe email validator with support of multiple validator.
upload_time2025-08-16 06:19:14
maintainerNone
docs_urlNone
authorNone
requires_python>=3.13
license# MIT License Copyright (c) 2025 Shailesh Pandit Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords composite-validator data-validation dns email email-validator mx-record python-validator regex type-safe-validation typed-validator validation validator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ๐Ÿ›ก๏ธ univalidator

[![PyPI version](https://img.shields.io/pypi/v/univalidator.svg)](https://pypi.org/project/univalidator/)
[![Python versions](https://img.shields.io/pypi/pyversions/univalidator.svg)](https://pypi.org/project/univalidator/)
[![License](https://img.shields.io/pypi/l/univalidator.svg)](https://github.com/shaileshpandit141/univalidator/blob/main/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:**
  
    ```bash
    uv add univalidator
    ````

- **By using pip:**

    ```bash
    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.

```python
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.

```python
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.

```python
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:

```python
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.

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

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

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

## ๐Ÿงช Testing

```bash
uv add pytest
uv run pytest tests
```

## ๐ŸŒŸ Example: Full Email Validation

```python
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](LICENSE).

## ๐Ÿ‘ค Author

For questions or assistance, contact **Shailesh** at [shaileshpandit141@gmail.com](mailto:shaileshpandit141@gmail.com).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "univalidator",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.13",
    "maintainer_email": null,
    "keywords": "composite-validator, data-validation, dns, email, email-validator, mx-record, python-validator, regex, type-safe-validation, typed-validator, validation, validator",
    "author": null,
    "author_email": "shaileshpandit141 <shaileshpandit141@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/1f/6a/7f993894619cdd9ced1d87f41bbfb18087f0505e17087b5561db2b7ac5f6/univalidator-0.2.1.tar.gz",
    "platform": null,
    "description": "# \ud83d\udee1\ufe0f univalidator\n\n[![PyPI version](https://img.shields.io/pypi/v/univalidator.svg)](https://pypi.org/project/univalidator/)\n[![Python versions](https://img.shields.io/pypi/pyversions/univalidator.svg)](https://pypi.org/project/univalidator/)\n[![License](https://img.shields.io/pypi/l/univalidator.svg)](https://github.com/shaileshpandit141/univalidator/blob/main/LICENSE)\n\nA **flexible, extensible, and type-safe** Python validation framework designed to validate data with ease.  \nCurrently supports **email validation** (via regex and MX records) and **composite validators** for running multiple checks.\n\n## \u2728 Features\n\n- **Abstract Validator Interface** \u2014 define your own validators easily.\n- **Regex-based Validation** \u2014 for any string patterns.\n- **Email Format Validation** \u2014 RFC-compliant pattern check.\n- **MX Record Validation** \u2014 verifies if an email domain can receive emails.\n- **Composite Validation** \u2014 run multiple validators in sequence.\n- **Type Safe** \u2014 written with modern Python type hints.\n\n## \ud83d\udce6 Installation\n\n- **By using uv:**\n  \n    ```bash\n    uv add univalidator\n    ````\n\n- **By using pip:**\n\n    ```bash\n    pip install univalidator\n    ````\n\n## \ud83d\udcda API Reference\n\n### **1\ufe0f BaseValidator[T]**\n\nAbstract base for all validators.\n**Custom validators** must implement the `validate(data: T) -> bool` method.\n\n### **2\ufe0f RegexValidator[T]**\n\nValidates data against a regular expression.\n\n```python\nfrom univalidator.validators import RegexValidator\n\nvalidator = RegexValidator[str](r\"^\\d{4}-\\d{2}-\\d{2}$\")  # YYYY-MM-DD format\nvalidator.validate(\"2025-08-15\")  # True\nvalidator.validate(\"15-08-2025\")  # False\n```\n\n### **3\ufe0f RegexEmailValidator[T]**\n\nValidates email format using a regex pattern.\nUses a default pattern, but you can pass your own.\n\n```python\nfrom univalidator.validators import RegexEmailValidator\n\nvalidator = RegexEmailValidator[str]()\nvalidator.validate(\"user@example.com\")  # True\nvalidator.validate(\"invalid-email\")     # False\n```\n\n### **4\ufe0f MXEmailRecordValidator[T]**\n\nChecks if an email\u2019s domain has MX DNS records.\n\n```python\nfrom univalidator.validators import MXEmailRecordValidator\n\nvalidator = MXEmailRecordValidator[str]()\nvalidator.validate(\"user@gmail.com\")  # True\nvalidator.validate(\"user@no-such-domain.com\")  # False\n```\n\nRestrict to specific domains:\n\n```python\nvalidator = MXEmailRecordValidator[str](allowed_domains=[\"example.com\", \"gmail.com\"])\n```\n\n### **5\ufe0f CompositeValidator[T]**\n\nRuns multiple validators in sequence.\nAll validators must pass for the data to be valid.\n\n```python\nfrom univalidator.composites import CompositeValidator\nfrom univalidator.validators import RegexEmailValidator, MXEmailRecordValidator\n\nvalidator = CompositeValidator[str]([\n    RegexEmailValidator(),\n    MXEmailRecordValidator()\n])\n\nvalidator.validate(\"user@gmail.com\")  # True\n```\n\n## \ud83e\uddea Testing\n\n```bash\nuv add pytest\nuv run pytest tests\n```\n\n## \ud83c\udf1f Example: Full Email Validation\n\n```python\nfrom univalidator.composites import CompositeValidator\nfrom univalidator.validators import RegexEmailValidator, MXEmailRecordValidator\n\nvalidator = CompositeValidator[str]([\n    RegexEmailValidator(),\n    MXEmailRecordValidator()\n])\n\nemail = \"test@gmail.com\"\nif validator.validate(email):\n    print(\"Valid email with active domain!\")\nelse:\n    print(\"Invalid email.\")\n```\n\n## \ud83d\udee0\ufe0f Planned Features\n\n- \ud83d\udd12 Add more Validators\n\n## \ud83e\udd1d Contributing\n\nContributions are welcome! Please open an issue or PR for any improvements.\n\n## \ud83d\udcdc License\n\nMIT License \u2014 See [LICENSE](LICENSE).\n\n## \ud83d\udc64 Author\n\nFor questions or assistance, contact **Shailesh** at [shaileshpandit141@gmail.com](mailto:shaileshpandit141@gmail.com).\n",
    "bugtrack_url": null,
    "license": "# MIT License  Copyright (c) 2025 Shailesh Pandit  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
    "summary": "A lightweight, type-safe email validator with support of multiple validator.",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/shaileshpandit141/univalidator",
        "Issues": "https://github.com/shaileshpandit141/univalidator/issues",
        "Repository": "https://github.com/shaileshpandit141/univalidator"
    },
    "split_keywords": [
        "composite-validator",
        " data-validation",
        " dns",
        " email",
        " email-validator",
        " mx-record",
        " python-validator",
        " regex",
        " type-safe-validation",
        " typed-validator",
        " validation",
        " validator"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "fc19ebda221b1a27ddd112834669789baf341747f6fa7b20b001f4757fe9f251",
                "md5": "7c3b66bff2e0d1369bdd5001d1885953",
                "sha256": "eb3fe8fff2145777327c9ef91f970d9b40c879c6b8b4d4e8c41edb42b9918d6a"
            },
            "downloads": -1,
            "filename": "univalidator-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7c3b66bff2e0d1369bdd5001d1885953",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.13",
            "size": 8901,
            "upload_time": "2025-08-16T06:19:12",
            "upload_time_iso_8601": "2025-08-16T06:19:12.208313Z",
            "url": "https://files.pythonhosted.org/packages/fc/19/ebda221b1a27ddd112834669789baf341747f6fa7b20b001f4757fe9f251/univalidator-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1f6a7f993894619cdd9ced1d87f41bbfb18087f0505e17087b5561db2b7ac5f6",
                "md5": "27b502030b3a3f361b884b25ef109f2e",
                "sha256": "6b5d0f6122f20e30cf2ecad492457b49796431b61dda4f2122c908aa479bc04c"
            },
            "downloads": -1,
            "filename": "univalidator-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "27b502030b3a3f361b884b25ef109f2e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.13",
            "size": 13000,
            "upload_time": "2025-08-16T06:19:14",
            "upload_time_iso_8601": "2025-08-16T06:19:14.309725Z",
            "url": "https://files.pythonhosted.org/packages/1f/6a/7f993894619cdd9ced1d87f41bbfb18087f0505e17087b5561db2b7ac5f6/univalidator-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-16 06:19:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "shaileshpandit141",
    "github_project": "univalidator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "univalidator"
}
        
Elapsed time: 0.84683s