pyvalidly


Namepyvalidly JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
SummaryLightweight, zero-dependency Python library for validating dictionaries with optional coercion and custom rules
upload_time2025-08-16 04:42:49
maintainerNone
docs_urlNone
authorNone
requires_python>=3.7
licenseMIT License Copyright (c) 2025 Dark00infinity 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 validation schema dict type-checking pydantic-alternative
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Pyvalidly

**Pyvalidly** is a lightweight, zero-dependency Python library for validating dictionaries with simple rules, custom functions, and optional coercion.

Inspired by Pydantic's power but built for simplicity, speed, and flexibility — especially useful when you want to avoid creating full-blown classes.

---

## Features

- Simple schema-based dictionary validation  
- Type validation – int, str, float, list, dict, custom classes.
- Coercion – Automatically convert types when possible.
- Default values – Fill missing fields with defaults.
- Conditional validation – Skip validation based on another field.
- Custom validation functions – Pass any callable returning True/False.
- Helper functions – is_email, is_url, min_value, max_value, min_length, max_length.
- Custom error messages – Per-field validation errors.
- Old-style and new-style schemas – Flexible for migration.

---

## Installation

```
pip install pyvalidly
```


## Basic Usage
### Old-style Schema
```
from pyvalidly import validate, is_email

schema = {
    "name": str, #(str,),
    "age": (int, lambda x: x > 18),
    "email": (str, is_email)
}

data = {
    "name": "John",
    "age": 25,
    "email": "john@example.com"
}

validated = validate(data, schema)
print(validated)
# {'name': 'John', 'age': 25, 'email': 'john@example.com'}


```

### New-style Schema

```
from pyvalidly import validate, is_email, min_value

schema = {
    "name": {"type": str, "required": True},
    "age": {"type": int, "coerce": True, "rules": [min_value(18)]},
    "email": {"type": str, "rules": [is_email]}
}

data = {
    "name": "John",
    "age": "42",
    "email": "john@example.com"
}

validated = validate(data,schema)
print(validated)
# {'name': 'John', 'age': 42, 'email': 'john@example.com'}

```

## Advanced Features
### 1. Type Coercion
```
from pyvalidly import validate, is_email, min_value

schema = {
    "age": {"type": int, "coerce": True}
}
data = {"age": "30"}

print(validate(data,schema))
# {'age': 30}

```

### 2. Default Values

```
from pyvalidly import validate, is_email, min_value

schema = {
    "name": {"type": str, "default": "Anonymous"}
}
data = {}

print(validate(data,schema))
# {'name': 'Anonymous'}

```

### 3. Conditional Validation

```
from pyvalidly import validate, is_email, min_value

schema = {
    "is_member": {"type": bool, "required": True},
    "membership_id": {
        "type": str,
        "required": True,
        "condition": lambda data: data.get("is_member") is True
    }
}

data = {"is_member": False}
print(validate(data, schema))
# {'is_member': False}

```

### 4. Custom Error Messages

```
from pyvalidly import validate, is_email, min_value
schema = {
    "age": {
        "type": int,
        "rules": [lambda x: x >= 18],
        "error": "Must be at least 18 years old"
    }
}
data = {"age": 10}

from pyvalidly.exceptions import ValidationError
try:
    print(validate(data, schema))
except ValidationError as e:
    print(e)
# Must be at least 18 years old

```

### 5. Built-in Helpers

```
from pyvalidly import is_email, is_url, min_value, max_value, min_length, max_length

print(is_email("test@example.com")) # True
print(is_url("http://example.com")) # True
print(min_value(10)(15)) # True
print(max_length(5)("hello")) # True

```

## Schema Styles

- Old-style tuple rules : 
Each field maps to a tuple of rules: (type, func, func, ...)

- New-style dict rules :
{ "type": str, "required": True, "default": "X", "rules": [func], "coerce": True, "condition": func }

## Project Structure
```
pyvalidly/
├── core.py
├── exceptions.py
├── validators.py
├── __init__.py
└── tests/
    └── test_core.py
```

## License

MIT License

## Contribute

Pull requests, suggestions, and stars are welcome!
If this helped you, consider supporting the project.

## Contact

Made with love by Deepak singh — https://github.com/dark00infinity

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pyvalidly",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "validation, schema, dict, type-checking, pydantic-alternative",
    "author": null,
    "author_email": "Deepak singh <deepaksingh20899@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/30/7c/4fcc2d5a8ff82c41c128e4a4b8987d840dc9c828608c17f1a00fe7bae869/pyvalidly-1.0.1.tar.gz",
    "platform": null,
    "description": "# Pyvalidly\r\n\r\n**Pyvalidly** is a lightweight, zero-dependency Python library for validating dictionaries with simple rules, custom functions, and optional coercion.\r\n\r\nInspired by Pydantic's power but built for simplicity, speed, and flexibility \u2014 especially useful when you want to avoid creating full-blown classes.\r\n\r\n---\r\n\r\n## Features\r\n\r\n- Simple schema-based dictionary validation  \r\n- Type validation \u2013 int, str, float, list, dict, custom classes.\r\n- Coercion \u2013 Automatically convert types when possible.\r\n- Default values \u2013 Fill missing fields with defaults.\r\n- Conditional validation \u2013 Skip validation based on another field.\r\n- Custom validation functions \u2013 Pass any callable returning True/False.\r\n- Helper functions \u2013 is_email, is_url, min_value, max_value, min_length, max_length.\r\n- Custom error messages \u2013 Per-field validation errors.\r\n- Old-style and new-style schemas \u2013 Flexible for migration.\r\n\r\n---\r\n\r\n## Installation\r\n\r\n```\r\npip install pyvalidly\r\n```\r\n\r\n\r\n## Basic Usage\r\n### Old-style Schema\r\n```\r\nfrom pyvalidly import validate, is_email\r\n\r\nschema = {\r\n    \"name\": str, #(str,),\r\n    \"age\": (int, lambda x: x > 18),\r\n    \"email\": (str, is_email)\r\n}\r\n\r\ndata = {\r\n    \"name\": \"John\",\r\n    \"age\": 25,\r\n    \"email\": \"john@example.com\"\r\n}\r\n\r\nvalidated = validate(data, schema)\r\nprint(validated)\r\n# {'name': 'John', 'age': 25, 'email': 'john@example.com'}\r\n\r\n\r\n```\r\n\r\n### New-style Schema\r\n\r\n```\r\nfrom pyvalidly import validate, is_email, min_value\r\n\r\nschema = {\r\n    \"name\": {\"type\": str, \"required\": True},\r\n    \"age\": {\"type\": int, \"coerce\": True, \"rules\": [min_value(18)]},\r\n    \"email\": {\"type\": str, \"rules\": [is_email]}\r\n}\r\n\r\ndata = {\r\n    \"name\": \"John\",\r\n    \"age\": \"42\",\r\n    \"email\": \"john@example.com\"\r\n}\r\n\r\nvalidated = validate(data,schema)\r\nprint(validated)\r\n# {'name': 'John', 'age': 42, 'email': 'john@example.com'}\r\n\r\n```\r\n\r\n## Advanced Features\r\n### 1. Type Coercion\r\n```\r\nfrom pyvalidly import validate, is_email, min_value\r\n\r\nschema = {\r\n    \"age\": {\"type\": int, \"coerce\": True}\r\n}\r\ndata = {\"age\": \"30\"}\r\n\r\nprint(validate(data,schema))\r\n# {'age': 30}\r\n\r\n```\r\n\r\n### 2. Default Values\r\n\r\n```\r\nfrom pyvalidly import validate, is_email, min_value\r\n\r\nschema = {\r\n    \"name\": {\"type\": str, \"default\": \"Anonymous\"}\r\n}\r\ndata = {}\r\n\r\nprint(validate(data,schema))\r\n# {'name': 'Anonymous'}\r\n\r\n```\r\n\r\n### 3. Conditional Validation\r\n\r\n```\r\nfrom pyvalidly import validate, is_email, min_value\r\n\r\nschema = {\r\n    \"is_member\": {\"type\": bool, \"required\": True},\r\n    \"membership_id\": {\r\n        \"type\": str,\r\n        \"required\": True,\r\n        \"condition\": lambda data: data.get(\"is_member\") is True\r\n    }\r\n}\r\n\r\ndata = {\"is_member\": False}\r\nprint(validate(data, schema))\r\n# {'is_member': False}\r\n\r\n```\r\n\r\n### 4. Custom Error Messages\r\n\r\n```\r\nfrom pyvalidly import validate, is_email, min_value\r\nschema = {\r\n    \"age\": {\r\n        \"type\": int,\r\n        \"rules\": [lambda x: x >= 18],\r\n        \"error\": \"Must be at least 18 years old\"\r\n    }\r\n}\r\ndata = {\"age\": 10}\r\n\r\nfrom pyvalidly.exceptions import ValidationError\r\ntry:\r\n    print(validate(data, schema))\r\nexcept ValidationError as e:\r\n    print(e)\r\n# Must be at least 18 years old\r\n\r\n```\r\n\r\n### 5. Built-in Helpers\r\n\r\n```\r\nfrom pyvalidly import is_email, is_url, min_value, max_value, min_length, max_length\r\n\r\nprint(is_email(\"test@example.com\")) # True\r\nprint(is_url(\"http://example.com\")) # True\r\nprint(min_value(10)(15)) # True\r\nprint(max_length(5)(\"hello\")) # True\r\n\r\n```\r\n\r\n## Schema Styles\r\n\r\n- Old-style tuple rules : \r\nEach field maps to a tuple of rules: (type, func, func, ...)\r\n\r\n- New-style dict rules :\r\n{ \"type\": str, \"required\": True, \"default\": \"X\", \"rules\": [func], \"coerce\": True, \"condition\": func }\r\n\r\n## Project Structure\r\n```\r\npyvalidly/\r\n\u251c\u2500\u2500 core.py\r\n\u251c\u2500\u2500 exceptions.py\r\n\u251c\u2500\u2500 validators.py\r\n\u251c\u2500\u2500 __init__.py\r\n\u2514\u2500\u2500 tests/\r\n    \u2514\u2500\u2500 test_core.py\r\n```\r\n\r\n## License\r\n\r\nMIT License\r\n\r\n## Contribute\r\n\r\nPull requests, suggestions, and stars are welcome!\r\nIf this helped you, consider supporting the project.\r\n\r\n## Contact\r\n\r\nMade with love by Deepak singh \u2014 https://github.com/dark00infinity\r\n",
    "bugtrack_url": null,
    "license": "MIT License\r\n        \r\n        Copyright (c) 2025 Dark00infinity\r\n        \r\n        Permission is hereby granted, free of charge, to any person obtaining a copy\r\n        of this software and associated documentation files (the \"Software\"), to deal\r\n        in the Software without restriction, including without limitation the rights\r\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r\n        copies of the Software, and to permit persons to whom the Software is\r\n        furnished to do so, subject to the following conditions:\r\n        \r\n        The above copyright notice and this permission notice shall be included in all\r\n        copies or substantial portions of the Software.\r\n        \r\n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r\n        SOFTWARE.\r\n        ",
    "summary": "Lightweight, zero-dependency Python library for validating dictionaries with optional coercion and custom rules",
    "version": "1.0.1",
    "project_urls": {
        "Repository": "https://github.com/dark00infinity/pyvalidly"
    },
    "split_keywords": [
        "validation",
        " schema",
        " dict",
        " type-checking",
        " pydantic-alternative"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "88147f9399453c1f4f7d1842fbbc6b10a836ed06ffa1b01b82f336608c1f1800",
                "md5": "4ddbfaf6e90913433c66c949ec271150",
                "sha256": "7baa9b6285bd8e9510e368ef2d7f9eae406b7e0718beb77a9b531a7fd494012a"
            },
            "downloads": -1,
            "filename": "pyvalidly-1.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4ddbfaf6e90913433c66c949ec271150",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 9244,
            "upload_time": "2025-08-16T04:42:47",
            "upload_time_iso_8601": "2025-08-16T04:42:47.738481Z",
            "url": "https://files.pythonhosted.org/packages/88/14/7f9399453c1f4f7d1842fbbc6b10a836ed06ffa1b01b82f336608c1f1800/pyvalidly-1.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "307c4fcc2d5a8ff82c41c128e4a4b8987d840dc9c828608c17f1a00fe7bae869",
                "md5": "60cdd1d434fc1539636819f1f0c96df9",
                "sha256": "c8e4e5c5e6e771cbfb5be8d8d5ddf8b8dc7e1dd644ea8b906c7f326f7e00d565"
            },
            "downloads": -1,
            "filename": "pyvalidly-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "60cdd1d434fc1539636819f1f0c96df9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 10425,
            "upload_time": "2025-08-16T04:42:49",
            "upload_time_iso_8601": "2025-08-16T04:42:49.257633Z",
            "url": "https://files.pythonhosted.org/packages/30/7c/4fcc2d5a8ff82c41c128e4a4b8987d840dc9c828608c17f1a00fe7bae869/pyvalidly-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-08-16 04:42:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "dark00infinity",
    "github_project": "pyvalidly",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pyvalidly"
}
        
Elapsed time: 1.60005s