Skip to main content

dvalidator validation attributes

Project description

Library for validating your object dictionary

from dvalidator.validator import Validator
import dvalidator.rules as rules


validator = Validator({
    'a': rules.required(),
    'b': rules.required('Field "b" not found'),
    'c': [rules.required(), rules.is_type(str, 'Field "c" is not str type')]
    })

d = {'a': 1, b: 2, c: '3'}

res, err = validator.validate(d)

print(res)
True

Other rules see in: https://github.com/kakabara/capybara/blob/master/capybara/rules.py

Also you can create custom validation method:

from dvalidator.validator import Validator
import dvalidator.rules as rules


def raise_on_exist(message='Found unexpected field in dict'):
    def check(field: str, dict_to_check: dict):
        if field in dict_to_check:
            return False, None
        else:
            return True, message
    return check

validator = Validator({
    'a': rules.required(),
    'b': raise_on_exist()
    })

d = {'a': 1, 'b': 2}

res, err = validator.validate(d)

print(res)
False

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for dvalidator, version 0.1.3
Filename, size File type Python version Upload date Hashes
Filename, size dvalidator-0.1.3.tar.gz (3.1 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page