vutils-validator


Namevutils-validator JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/i386x/vutils-validator
SummaryData validation utilities
upload_time2024-02-19 17:29:20
maintainer
docs_urlNone
authorJiří Kučera
requires_python<4,>=3.7
licenseMIT
keywords data schema validation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![Coverage Status](https://coveralls.io/repos/github/i386x/vutils-validator/badge.svg?branch=main)](https://coveralls.io/github/i386x/vutils-validator?branch=main)
![CodeQL](https://github.com/i386x/vutils-validator/actions/workflows/codeql.yml/badge.svg)

# vutils-validator: Data Validation Utilities

This package provides a set of tools that helps with validation of input data.

## Installation

To get the package on your system, type
```sh
$ pip install vutils-validator
```

## How to Use

Please, read the following subsections to get more info about particular use
case.

### Basic Validations

Module `vutils.validator.basic` provides a set of functions for validation of
simple input data forms, like email addresses:
* `verify_not_empty(value)` fails if `value` is empty.
* `verify_matches(value, regex, message="")` fails if `value` does not match
  regular expression `regex`. Since many regular expressions describe entities
  that have a name (identifier, number, email address, etc.) the default error
  message can be overridden by `message` argument.
* `verify_email(value)` fails if `value` is not an email address (currently
  described by simple `^\S+@\S+\.[A-Za-z]+$` regular expression).

The `value` passed to all validation functions can be either `str` or a
`ValueHolder` (from `vutils.validator.value`) object. A `ValueHolder` object
can be used to store additional information about value, like its name and
origin. The synopsis of `ValueHolder`'s constructor is
`__init__(self, value, name="The value", location=None)`, where `value`,
`name`, and `location` are value, its name, and the location of its origin,
respectively. `location` is a `Location` (from `vutils.validator.value`) object
that holds path, line, and column of the value/token origin. `ValueHolder`
serves to provide more detail about value in error messages issued by
validation functions by raising `ValidationError` (from
`vutils.validator.errors`) when the validation fails, example:
```python
from vutils.validator.basic import verify_email
from vutils.validator.errors import ValidationError
from vutils.validator.value import ValueHolder


def get_input(name):
    return ValueHolder(input(f"Enter {name}: "), name)


try:
    verify_email(get_input("email"))
except ValidationError as exc:
    print(exc)
```

On ill-formed input, the example prints `email must be an email address!`,
since `get_input` names a value as `email`.

### Schema Validation

Module `vutils.validator.schema` provides function `validate(data, schema)` for
`data` validation against JSON schema `schema`. Function returns `None` in case
of valid `data` or list of `jsonschema.exceptions.{Validation,Schema}Error` in
case of invalid `data` or `schema`.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/i386x/vutils-validator",
    "name": "vutils-validator",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "<4,>=3.7",
    "maintainer_email": "",
    "keywords": "data,schema,validation",
    "author": "Ji\u0159\u00ed Ku\u010dera",
    "author_email": "sanczes@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ff/5b/89242aaf94e6162c0098d5d814f1fcf3dbb664cbd8ef97d614b74ff9966a/vutils-validator-0.2.0.tar.gz",
    "platform": "any",
    "description": "[![Coverage Status](https://coveralls.io/repos/github/i386x/vutils-validator/badge.svg?branch=main)](https://coveralls.io/github/i386x/vutils-validator?branch=main)\n![CodeQL](https://github.com/i386x/vutils-validator/actions/workflows/codeql.yml/badge.svg)\n\n# vutils-validator: Data Validation Utilities\n\nThis package provides a set of tools that helps with validation of input data.\n\n## Installation\n\nTo get the package on your system, type\n```sh\n$ pip install vutils-validator\n```\n\n## How to Use\n\nPlease, read the following subsections to get more info about particular use\ncase.\n\n### Basic Validations\n\nModule `vutils.validator.basic` provides a set of functions for validation of\nsimple input data forms, like email addresses:\n* `verify_not_empty(value)` fails if `value` is empty.\n* `verify_matches(value, regex, message=\"\")` fails if `value` does not match\n  regular expression `regex`. Since many regular expressions describe entities\n  that have a name (identifier, number, email address, etc.) the default error\n  message can be overridden by `message` argument.\n* `verify_email(value)` fails if `value` is not an email address (currently\n  described by simple `^\\S+@\\S+\\.[A-Za-z]+$` regular expression).\n\nThe `value` passed to all validation functions can be either `str` or a\n`ValueHolder` (from `vutils.validator.value`) object. A `ValueHolder` object\ncan be used to store additional information about value, like its name and\norigin. The synopsis of `ValueHolder`'s constructor is\n`__init__(self, value, name=\"The value\", location=None)`, where `value`,\n`name`, and `location` are value, its name, and the location of its origin,\nrespectively. `location` is a `Location` (from `vutils.validator.value`) object\nthat holds path, line, and column of the value/token origin. `ValueHolder`\nserves to provide more detail about value in error messages issued by\nvalidation functions by raising `ValidationError` (from\n`vutils.validator.errors`) when the validation fails, example:\n```python\nfrom vutils.validator.basic import verify_email\nfrom vutils.validator.errors import ValidationError\nfrom vutils.validator.value import ValueHolder\n\n\ndef get_input(name):\n    return ValueHolder(input(f\"Enter {name}: \"), name)\n\n\ntry:\n    verify_email(get_input(\"email\"))\nexcept ValidationError as exc:\n    print(exc)\n```\n\nOn ill-formed input, the example prints `email must be an email address!`,\nsince `get_input` names a value as `email`.\n\n### Schema Validation\n\nModule `vutils.validator.schema` provides function `validate(data, schema)` for\n`data` validation against JSON schema `schema`. Function returns `None` in case\nof valid `data` or list of `jsonschema.exceptions.{Validation,Schema}Error` in\ncase of invalid `data` or `schema`.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Data validation utilities",
    "version": "0.2.0",
    "project_urls": {
        "Bug Reports": "https://github.com/i386x/vutils-validator/issues",
        "Homepage": "https://github.com/i386x/vutils-validator",
        "Source": "https://github.com/i386x/vutils-validator"
    },
    "split_keywords": [
        "data",
        "schema",
        "validation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f44380f35aaf6523a6d64b092d48bde13f35f383a341d41ed6942d3c06cd92da",
                "md5": "f29b795f579fa77fd75ac3d406943ba5",
                "sha256": "2461a8d5960bfa9904ffb42f9205dae494c9c697b76700dcd041cd6598a84eb0"
            },
            "downloads": -1,
            "filename": "vutils_validator-0.2.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f29b795f579fa77fd75ac3d406943ba5",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": "<4,>=3.7",
            "size": 8709,
            "upload_time": "2024-02-19T17:29:19",
            "upload_time_iso_8601": "2024-02-19T17:29:19.011158Z",
            "url": "https://files.pythonhosted.org/packages/f4/43/80f35aaf6523a6d64b092d48bde13f35f383a341d41ed6942d3c06cd92da/vutils_validator-0.2.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ff5b89242aaf94e6162c0098d5d814f1fcf3dbb664cbd8ef97d614b74ff9966a",
                "md5": "0e6071e8304658f473a828a51175389a",
                "sha256": "3ed287c48572fb28c2effa415bf6fbbfd2adb3ea6c791071d502e077819e76f9"
            },
            "downloads": -1,
            "filename": "vutils-validator-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0e6071e8304658f473a828a51175389a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.7",
            "size": 12699,
            "upload_time": "2024-02-19T17:29:20",
            "upload_time_iso_8601": "2024-02-19T17:29:20.864647Z",
            "url": "https://files.pythonhosted.org/packages/ff/5b/89242aaf94e6162c0098d5d814f1fcf3dbb664cbd8ef97d614b74ff9966a/vutils-validator-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-19 17:29:20",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "i386x",
    "github_project": "vutils-validator",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "vutils-validator"
}
        
Elapsed time: 0.18314s