Skip to main content

No project description provided

Project description

Installation

You can install it directly from PyPi https://pypi.org/project/easyvalid-data-validator/

  pip install easyvalid-data-validator

Tests

All functions are fully tested

You are able to run tests on your own cloning repo and using it's environment:

  git clone https://github.com/DSmolke/EASYVALID_DATA_VALIDATOR.git
  cd EASYVALID_DATA_VALIDATOR

poetry:

  poetry update
  poetry shell
  poetry run python -m unittest discover -v

or:

  poetry run pytest -vv

pipenv:

  pipenv shell
  pipenv run python -m unittest discover -v

or:

  pipenv run pytest -vv

pip:

  python -m unittest discover -v

or:

  pip install pytest
  pytest -vv

easyvalid-data-validator

It's a package developed mainly for validation of json dict that is created by using json.load().

Here is an example of json dict, that has name, age, and balance.

user = {
    "name": "ADAM",
    "age": 18,
    "balance": "2000.00"
}

We want to validate if:

  • name contain only uppercase letters,
  • age is greater or equal to 18,
  • balance is valid for Decimal conversion

We need to prepare constraint dict which describes this rules as explained:

constraints = {
    "key_name1": {<ConstraintEnumObject>: *args},
    "key_name2": {<ConstraintEnumObject>: *args},
    "key_name3": {<ConstraintEnumObject>: *args}
}

So we create dict that stores dicts containing Constraint Objects as key that are indicators for validator of which case it's currently working on, and what datachecker it should use. Value should be arguments that datachecker need:

  • Constraint Object - Enum object
  • datachecker - function that takes needed arguments and returns True or False if condition is mached
  • validator - validator function that raises error when any of value is not valid, or returns data when it's valid
from easyvalid_data_validator.constraints import Constraint

constraints = {
    "name": {Constraint.STRING_REGEX: r'^[A-Z]+$'},
    "age": {Constraint.INT_GE: 18},
    "balance": {Constraint.STRING_IS_DECIMAL: None}
}

Validation is very easy now, we just need to provide validate_json_data() with json_data, and constraints:

from easyvalid_data_validator.validator import validate_json_data

result = validate_json_data(user, constraints)

# result --> {"name": "ADAM", "age": 18, "balance": "2000.00"}

If we would change age of user to 17, validator would throw an error:

ValidationError("age": ["Invalid integer expression - isn't grater or equal to compare value"])

Documentation link

Click to read documentation

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

easyvalid_data_validator-2.0.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

easyvalid_data_validator-2.0.1-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file easyvalid_data_validator-2.0.1.tar.gz.

File metadata

  • Download URL: easyvalid_data_validator-2.0.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Windows/10

File hashes

Hashes for easyvalid_data_validator-2.0.1.tar.gz
Algorithm Hash digest
SHA256 1bfc2e166207bc863c863398c8138ca964aa3441632b800028f63b6991acec9d
MD5 dd2c37b12ae64dcd1d98ed15aa07f50d
BLAKE2b-256 b6264b4f2a3ffe8d371663c1382229520883b47c7f8bac3fbcbbc6bc436b1707

See more details on using hashes here.

File details

Details for the file easyvalid_data_validator-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for easyvalid_data_validator-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3d800bcf0dcf98c751b575a1496fc1cbff1c53badc11fa918c1bbb0cf51b0a5b
MD5 f80ec5f26f9856be8d1fe1b5b869f8cf
BLAKE2b-256 6b63f4704c8b6e35e762cc2313eb0c855f2e4f24752c9be1e9312957a7f9a406

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